Error: spawn wslvar ENOENT when running yarn storybook on WSL2

Error: spawn wslvar ENOENT when running yarn storybook on WSL2

我正尝试在 https://storybook.js.org/tutorials/intro-to-storybook/react/en/get-started/

上学习本教程

教程中给出的命令如下

# Clone the template
npx degit chromaui/intro-storybook-react-template taskbox

cd taskbox

# Install dependencies
yarn

# Run the test runner (Jest) in a terminal:
yarn test --watchAll

# Start the component explorer on port 6006:
yarn storybook

# Run the frontend app proper on port 3000:
yarn start

然而,当我的 wsl2 ubuntu 终端上 yarn storybook 时,我 运行 遇到了问题。

这里是错误

yarn storybook
yarn run v1.22.5
warning ../package.json: No license field
$ start-storybook -p 6006 -s public
info @storybook/react v6.3.0
info
info => Loading presets
info => Serving static files from ./public at /
info => Loading 1 config file in "/mnt/d/taskbox/.storybook"
info => Loading 9 other files in "/mnt/d/taskbox/.storybook"
info => Adding stories defined in "/mnt/d/taskbox/.storybook/main.js"
info => Using prebuilt manager
info => Loading Webpack configuration from `node_modules/react-scripts`
info => Removing existing JavaScript and TypeScript rules.
info => Modifying Create React App rules.
info => Using default Webpack4 setup
(node:7126) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /mnt/d/taskbox/node_modules/postcss-safe-parser/node_modules/postcss/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
17% building 63/88 modules 25 active /mnt/d/taskbox/node_modules/global/window.jsBrowserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
webpack built preview 0ef1297f848efab9f24c in 139265ms
╭─────────────────────────────────────────────────────╮
│                                                     │
│   Storybook 6.3.0 started                           │
│   3.97 min for preview                              │
│                                                     │
│    Local:            http://localhost:6006/         │
│    On your network:  http://172.22.229.210:6006/    │
│                                                     │
│   A new version (6.3.6) is available!               │
│                                                     │
│   Upgrade now: npx sb@latest upgrade                │
│                                                     │
│   Read full changelog: https://git.io/fhFYe         │
│                                                     │
╰─────────────────────────────────────────────────────╯
node:internal/errors:456
    ErrorCaptureStackTrace(err);
    ^

Error: spawn wslvar ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
    at onErrorNT (node:internal/child_process:480:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn wslvar',
  path: 'wslvar',
  spawnargs: [ 'systemroot' ],
  cmd: 'wslvar systemroot',
  stdout: '',
  stderr: ''
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我一直很难找到类似的错误,因为它似乎是一个罕见的错误。不过,我怀疑这与我有关 运行 WSL2 上的故事书。

根据this Github comment,错误通常是由以下任一原因引起的:

  • powershell.exe 不在路径中(不太可能,但如果 /etc/wsl.conf 明确禁用 Windows PATH 互操作,则可能是这种情况)。
  • 缺少 wslvar,它是 wslu(WSL 实用程序)包的一部分。虽然它默认安装在某些 WSL 发行版中,但它可能不是最新的或未安装在某些 WSL 发行版中。有关每个发行版的安装说明,请参阅 Github 页面。