“没有为命令 npm 设置版本”.tool-versions 文件丢失

Any*_*nya 4 config node.js npm

我正在尝试在 VS Code 中创建我的 React 应用程序。安装node.js(V 18.12.1)后,我运行代码来创建我的应用程序并收到以下响应:

npm create-react-app example

No version is set for command npm Consider adding one of the following versions in your config file at nodejs 16.15.0 nodejs 16.17.0 nodejs 16.17.1 nodejs 16.18.0 nodejs 16.18.1

我尝试重新安装 node.js 并认为问题可能是由于缺少 .tools-version 文件,但我不知道如何创建它。

ste*_*nja 5

来这里寻找一个非常相似的错误。我刚刚使用版本管理器asdf设置并安装了 NodeJS LTS ( asdf install nodejs lts),然后运行npx命令并收到以下错误。

No version is set for command npx
Consider adding one of the following versions in your config file at 
nodejs 18.12.1
nodejs lts
Run Code Online (Sandbox Code Playgroud)

第二行末尾没有路径,但考虑到有关设置版本的错误和 asdf 说明,我在全局文件中配置了 NodeJS 版本.tool-versions,这解决了我的问题:

No version is set for command npx
Consider adding one of the following versions in your config file at 
nodejs 18.12.1
nodejs lts
Run Code Online (Sandbox Code Playgroud)

Manu Jo Varghese 对于检查您的安装和环境有一些很好的建议!加上:

  1. which node:在你的路径中找到NodeJS程序
  2. bash 或 zsh -> 检查您所在的 shell,然后根据情况检查 .bashrc 或 .zshrc 文件