简体   繁体   English

我收到路径错误:[找不到模块] 每当我尝试在 VS Code 中运行任何与 npm 相关的命令时

[英]I got path error : [module not found] whenever I try to run any npm related command in VS Code

Whenever I try to run any npm related command such as npm -v or npm install , it gives me the error:每当我尝试运行任何与 npm 相关的命令(例如npm -vnpm install )时,都会出现错误:

在此处输入图片说明

From the screenshot, you can see that it is trying to navigate to find the module but the module can not be found at:从屏幕截图中,您可以看到它正在尝试导航以查找模块,但无法在以下位置找到该模块:

C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\node_modules\\npm\\bin\\npm-cli.js

Actually, the location of the npm-cli in my system is:实际上,npm-cli 在我的系统中的位置是:

C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js

In fact, I have set the path in the environment variable like this:事实上,我已经在环境变量中设置了这样的路径:

User variables:用户变量:

在此处输入图片说明

System variables:系统变量:

在此处输入图片说明

The solution I got is to run this command every time I want to run any npm related command:我得到的解决方案是每次我想运行任何 npm 相关命令时都运行此命令:

SET PATH=C:\Program Files\Nodejs;%PATH%

But it is not a solution to run this command in the terminal every time I start working on my project in VS Code.但是每次我开始在 VS Code 中处理我的项目时,都不能在终端中运行此命令。 I want to permanently set the path in the environment variable.我想在环境变量中永久设置路径。

How can I resolve this?我该如何解决这个问题?

Same issue, this was first major post I saw, so adding my fix for others who find themselves here.同样的问题,这是我看到的第一篇重要帖子,因此为其他发现自己在这里的人添加了我的修复程序。 Hope it's helpful:希望有帮助:

Restart PC, open VS Code, and delete any terminal instances that are still open, as they will not inherit the new path(s) if they are 'session-restored'.重新启动 PC,打开 VS Code,并删除任何仍然打开的终端实例,因为如果它们是“会话恢复”,它们将不会继承新路径。

My root cause was updating Node, which for whatever reason prefaced an environmental variable in $PATH$ with a semi-colon ';'.我的根本原因是更新 Node,无论出于何种原因,它都在 $PATH$ 中的环境变量前面加上了一个分号“;”。 Worked in external cmd.exe, but didn't work in VS Code integrated terminal until I realized I had to restart the old ones.在外部 cmd.exe 中工作,但在 VS Code 集成终端中无法工作,直到我意识到我必须重新启动旧的。

This thread was the one that eventually got me there: VS Code terminal doesn't recognize PATH variables这个线程是最终让我到达那里的线程: VS Code 终端无法识别 PATH 变量

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每当我尝试使用 Next.js 运行“npm run dev”时,都找不到错误模块 - ERROR MODULE NOT FOUND whenever I try to run 'npm run dev' using Next.js 每当我尝试在 Visual Studio 代码上运行“npm install”时出现错误 - I get an error whenever i try to run "npm install" on visual studio code 我无法通过 npm 运行命令运行脚本。 我的脚本名称是“开始”。 每当我通过此命令运行此脚本时,我都会收到错误 - I'm unable to run the script through npm run command. My script name is “start”. whenever i run this script through this command i got error 当我尝试使用npm安装任何模块时,它将引发错误EMAXREDIRECT - When I try to install any module with npm, it throws error EMAXREDIRECT 当我尝试使用npm start命令运行React App时出错 - Error when I try run a React App with npm start command 无论我尝试什么,npm'找不到命令' - npm 'command not found' no matter what I try 每当我尝试通过 Heroku 运行我的服务器时,我都会收到“错误:找不到模块 'dotenv'” - Whenever I try to run my server via Heroku I get "Error: Cannot find module 'dotenv'" 我尝试在终端中执行 npm run dev 命令时出现 Npm 错误 - Npm Error while i try to execute npm run dev command in my terminal 当我尝试运行npm install时出错 - Error when I try to run npm install 当我尝试在 Windows 命令提示符下运行 `npm run test` 时出错 - Error when I try to run `npm run test` in windows command prompt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM