node.js 运行 npm 时找不到 npm-cli.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24721903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm-cli.js not found when running npm
提问by user1192476
Usually I can install a library using npmbut today when installing yeoman I encountered this errors. Please help to figure out what's root cause.
通常我可以使用npm安装一个库,但是今天在安装 yeoman 时我遇到了这个错误。请帮助找出根本原因。
D:\Works\phonegap\ionic\todo>npm install -g yo
module.js:340
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I looked into the folder:
我查看了文件夹:
C:\Program Files\nodejs\node_modules\npm\bin\
C:\Program Files\nodejs\node_modules\npm\bin\
but don't see node_modulesfolder as the error described.
但没有看到node_modules文件夹作为错误描述。
I also try to find npm-cli.jsand see it's actually in C:\Program Files\nodejs\node_modules\npm\bin\
我也尝试找到npm-cli.js并查看它实际上在C:\Program Files\nodejs\node_modules\npm\bin\
回答by user1192476
It turns out the issue is due to the wrong path of node in system variable. The path is currently pointing to
事实证明,问题是由于系统变量中节点的错误路径造成的。路径当前指向
(I really don't know when I modified it)
(我真的不知道我什么时候修改过)
C:\Program Files\nodejs\node_modules\npm\bin
so I change to
所以我改成
C:\Program Files\nodejs
and it works like a charm.
它就像一个魅力。
回答by Prathap Kudupu
You need to run this in the command line.
您需要在命令行中运行它。
SET PATH=C:\Program Files\Nodejs;%PATH%
回答by Peter Sun
You may also have this problem if in your path you have C:\Program Files\nodejsand C:\Program Files\nodejs\node_modules\npm\bin. Remove the latter from the path
如果在您的路径中有C:\Program Files\nodejs和,您也可能会遇到此问题C:\Program Files\nodejs\node_modules\npm\bin。从路径中删除后者
回答by Manoj
Copy the directory named npmfrom your installed node path (In my case the npm directory was available in C:\Program Files\nodejs\node_modules).
复制npm从您安装的节点路径命名的目录(在我的情况下,npm 目录在 中可用C:\Program Files\nodejs\node_modules)。
Navigate to C:\Users\%USERNAME%\AppData\Roaming\npm\node_modulesand paste the copied npmdirectory there.
导航到C:\Users\%USERNAME%\AppData\Roaming\npm\node_modules并粘贴复制的npm目录。
This method worked for me when I had the same error. . .
当我遇到同样的错误时,这种方法对我有用。. .
回答by 3AK
I just repaired my NodeJS installation and it worked for me!
我刚刚修复了我的 NodeJS 安装,它对我有用!
Go to Control Panel\All Control Panel Items\Programs and Features--> find NodeJSand choose option repair to repair it. Hope this helps.
转到Control Panel\All Control Panel Items\Programs and Features--> 查找NodeJS并选择选项修复来修复它。希望这可以帮助。
回答by admax
This not the same case as in the question, but might be helpful for someone facing the similar issue. On Windows, if you are calling npmcommands from some CI/automation tool, you might run into the error:
这与问题中的情况不同,但可能对面临类似问题的人有所帮助。在 Windows 上,如果您npm从某个 CI/自动化工具调用命令,您可能会遇到错误:
Error: Cannot find module 'SOME_PATH\node_modules\npm\bin\npm-cli.js'
where SOME_PATHis not Program Files/...but some project directory instead. So npm tries to find npm-cli.js inside the project root directory instead of searching it in Program Files/nodejs.
whereSOME_PATH不是Program Files/...而是一些项目目录。所以 npm 尝试在项目根目录中查找 npm-cli.js 而不是在Program Files/nodejs.
The reason is npm.cmd script:
原因是 npm.cmd 脚本:
:: Created by npm, please don't edit manually.
@ECHO OFF
SETLOCAL
SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
SET "NODE_EXE=node"
)
SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)
"%NODE_EXE%" "%NPM_CLI_JS%" %*
This script uses %~dp0to lookup the npm-cli.js but some automation tools could set work directory in the way that %~dp0points to the local project dir so the script works incorrectly.
此脚本用于%~dp0查找 npm-cli.js,但某些自动化工具可能会以%~dp0指向本地项目目录的方式设置工作目录,因此脚本无法正常工作。
One possible solution could be changing the npm calls from this
一种可能的解决方案可能是从此更改 npm 调用
npm.cmd install
to this
对此
cmd.exe /c npm.cmd install
回答by edi9999
None of the other answers worked for me.
其他答案都不适合我。
Here is what I write (in a git bash shell on windows ):
这是我写的(在 windows 上的 git bash shell 中):
PATH="/c/Program Files/nodejs/:$PATH" npm run yeoman
回答by TARJU
Don't change any environment variables
不要更改任何环境变量
It was the installer which caused the issue and did not install all the required file.
是安装程序导致了问题并且没有安装所有必需的文件。
I just repaired the NODEJS setup on windows 7 and it works very well. May be you can reinstall, just incase something does not work.
我刚刚修复了 Windows 7 上的 NODEJS 设置,效果很好。也许你可以重新安装,以防万一某些东西不起作用。
回答by RedYeti
On a Mac:
在 Mac 上:
I was running this out of the Maven com.github.eirslett Frontend Plugin when I had the same error.
当我遇到同样的错误时,我正在使用 Maven com.github.eirslett Frontend Plugin 运行它。
Eventually I had to:
最终我不得不:
Install Node.js via the installer download here: http://nodejs.org/
通过此处的安装程序下载安装 Node.js:http: //nodejs.org/
Delete all the node/and node_modules/folders from within my maven build structure.
从我的 Maven 构建结构中删除所有node/和node_modules/文件夹。
回答by olagu
I encountered the same problem with node 8.5 when installed with nvm. The below solution worked for me
我在安装 nvm 时遇到了与 node 8.5 相同的问题。以下解决方案对我有用
$ nvm uninstall 8.5
8.5.0
Uninstalling node v8.5.0...Error removing node v8.5.0
Manually remove C:\Users\Omkar\AppData\Roaming\nvm\v8.5.0.
$ nvm install 8.5
8.5.0
Downloading node.js version 8.5.0 (64-bit)...
Complete
Creating C:\Users\Omkar\AppData\Roaming\nvm\temp
Downloading npm version 5.3.0... Complete
Installing npm v5.3.0...
Installation complete. If you want to use this version, type
nvm use 8.5.0
Omkar@VAST-0137 MINGW64 /d/code
This worked for me cause node 8.5 was not correctly installed before with nvm. I figured it out cause "npm\bin\npm-cli.js" folders and files were not created inside node_modules before.
这对我有用,因为在使用 nvm 之前没有正确安装节点 8.5。我发现原因是“npm\bin\npm-cli.js”文件夹和文件之前没有在 node_modules 中创建。

