[英]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 -v或npm 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.