进程失败:生成 C:\WINDOWS\system32\cmd.exe ENOENT Jest 进程 "watch-tests" 以 wsl 2 和 jest 扩展意外结束

Process failed: spawn C:\WINDOWS\system32\cmd.exe ENOENT Jest process "watch-tests" ended unexpectedly with wsl 2 and jest extension

我 运行宁 vscode 在 wsl2 中使用 orta.vscode-jest 扩展。当我通过 powershell 打开 vscode 时,扩展可以正常工作,但是当我通过 wsl2 打开 运行 vscode 时,我收到以下错误:

我也收到以下错误

not-test onProcessExit: process exit with code=4294963238, signal=undefined
 see troubleshooting: https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting
'\wsl.localhost\Ubuntu\home\{mypath}\wwwroot'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Windows\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Windows\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Roaming\npm-cache\_logs21-09-13T16_50_21_922Z-debug.log
Jest process "watch-tests" ended unexpectedly
 see troubleshooting: https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting

运行在 React 应用程序中使用 package.json

中的这些有趣设置
 "jest": {
    "coverageReporters": [
      "lcov",
      "text"
    ],
    "coveragePathIgnorePatterns": [
      "src/index.tsx",
      "src/locales/"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 84,
        "functions": 85,
        "lines": 85,
        "statements": 85
      }
    }
  }

我可以使用“npm 运行 coverage”从 cli 运行 我的覆盖范围,其中覆盖脚本定义如下:

react-scripts test --coverage --resetMocks=false

但我希望手表功能正常工作。

如有任何帮助,我们将不胜感激!

我发现问题是我在 powershell 中启动 vscode 而我本应在 wsl 中启动它。

编辑:抱歉,我最初的描述有点不清楚。我会尽力详细说明。通常,我会通过导航到文件资源管理器中的文件夹和 select“使用代码打开”来打开 vscode。我相信我的“使用代码打开”没有启动 wsl 2 实例,即使它在我的 wsl 路径中。我通过在该目录中打开 wsl2 并 selecting “代码”来修复它。我确定还有另一种方法可以在 powershell 中启动 wsl 2 实例,但我还没有尝试过。