Yarn 在 VS Code 中找不到节点

问题描述 投票:0回答:1

当我在 VS Code 中使用 PowerShell 运行

yarn
时。我收到这样的消息:

yarn

yarn install v1.22.22
$ node preinstall.js
'node' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

但是如果我使用 Windows PowerShell(不是在 VS Code 中)运行,它就可以工作。如果我在 VS Code 中使用其他终端(例如 git bash)运行,它也可以工作。

版本:

  • VS 代码:2024 年 4 月(版本 1.89)
  • 节点:20.12.2
  • 纱线:22.22.1

我已经运行了

set-ExecutionPolicy RemoteSigned
,但是问题仍然存在。我还重新安装了 Node.js 和 Yarn。

node.js visual-studio-code yarnpkg
1个回答
0
投票

检查 PATH 变量:如果安装了 Node.js 但您仍然遇到问题,您可能需要检查包含 Node.js 可执行文件的目录是否已添加到系统的 PATH 变量中。 要进行检查,请在 PowerShell 终端中键入 echo $env:PATH。这将显示 PATH 变量的当前值。 如果包含 Node.js 的目录未在 PATH 变量中列出,您需要添加它。 您可以使用以下命令临时将其添加到当前会话: 电源外壳 复制代码 $env:PATH += ";C:\路径 o 颂” 替换 C:\路径 o ode 与系统上安装 Node.js 的实际路径。 重新启动 VS Code:更改 PATH 变量后,重新启动 VS Code 以确保更改生效。

© www.soinside.com 2019 - 2024. All rights reserved.