我不能在NodeJS中使用命令提示符使用npm install。我在运行npm install时得到这些错误:

module.js:339
    throw err;
    ^
Error: Cannot find module 'semver'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\npm\l
ib\config\defaults.js:6:14)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)

当前回答

提醒一下,可执行npm通过node env执行:

xb@dnxb:/tmp$ type -a npm
npm is /usr/bin/npm
npm is /bin/npm
xb@dnxb:/tmp$ realpath /usr/bin/npm /bin/npm
/usr/share/npm/bin/npm-cli.js
/usr/share/npm/bin/npm-cli.js
xb@dnxb:/tmp$ 
xb@dnxb:/tmp$ head -1 /usr/share/npm/bin/npm-cli.js
#!/usr/bin/env node

我可以通过-a类型检查哪个节点被选择,第一行具有最优先级,即,如果我运行/usr/local/bin/node /usr/share/npm/bin/npm-cli.js,我可以得到相同的错误,但如果我运行/usr/bin/node /usr/share/npm/bin/npm-cli.js,则没有错误:

xb@dnxb:/tmp$ type -a node
node is /usr/local/bin/node
node is /usr/bin/node
node is /bin/node
xb@dnxb:/tmp$ realpath /usr/local/bin/node
/usr/local/bin/node
xb@dnxb:/tmp$ realpath /usr/bin/node
/usr/bin/node
xb@dnxb:/tmp$ realpath /bin/node
/usr/bin/node
xb@dnxb:/tmp$ 

有2个唯一的基于realpath的节点exe。如果你有类似的情况,那么你需要找出如何删除不需要的/损坏的节点exe,例如sudo rm /usr/local/bin/node或操纵env $PATH。

其他回答

我也有这个,在昨天运行brew安装纱线后。至少,在那之前一切都很好。

我运行rm -rf node_modules并尝试重新安装,但没有npm命令工作。

最后,我采取了相当简单的步骤,通过Mac OS X的官方Node安装程序重新安装Node。

https://nodejs.org/en/download/

现在一切都好了。回到目录,运行npm install,它就完成了。

在brew在我的MacOs Sierra 10.12.6上安装纱线后,我也遇到了同样的麻烦。(并且在brew更新自我后第一次尝试安装,并提示“Homebrew必须在Ruby 2.3下运行!”您正在运行2.0.0。(RuntimeError)”。所以我重新运行了一遍。)

所以我使用n管理器重新安装npm。

通过参数为空的“n”命令切换到另一个节点版本(在我的例子中是8.0) 或者通过“n x.x.x”安装new,其中x.x.x为节点版本号(我需要6.9.1) 删除工作版本号为“n rm x.x.x”,其中x.x.x为节点版本号。如果需要,请使用sudo 通过“n x.x.x”安装工作版本号,其中x.x.x表示节点版本号。如果需要,请使用sudo 切换到节点的工作版本。(参考第一步)

我想问题可能是在sudo下安装的节点。

重新开始。

brew uninstall --force node
brew install node

只需删除/node_modules文件夹,然后重试。,)

你可以使用npm rm来删除它。

你也可以在GitHub上检查这个问题。 更具体地说,unnistal是这样的:

Uninstalling So sad to see you go. sudo npm uninstall npm -g Or, if that fails, sudo make uninstall More Severe Uninstalling Usually, the above instructions are sufficient. That will remove npm, but leave behind anything you've installed. If you would like to remove all the packages that you have installed, then you can use the npm ls command to find them, and then npm rm to remove them. To remove cruft left behind by npm 0.x, you can use the included clean-old.sh script file. You can run it conveniently like this: npm explore npm -g -- sh scripts/clean-old.sh npm uses two configuration files, one for per-user configs, and another for global (every-user) configs. You can view them by doing: npm config get userconfig # defaults to ~/.npmrc npm config get globalconfig # defaults to /usr/local/etc/npmrc Uninstalling npm does not remove configuration files by default. You must remove them yourself manually if you want them gone. Note that this means that future npm installs will not remember the settings that you have chosen.

我得到一个错误说权限被拒绝后运行任何'ng'命令(ng——版本)。我谷歌了一下,尝试清除npm缓存npm缓存验证,卸载我的全局angular cli (npm uninstall -g @angular/cli),重新安装angular/cli (npm install -g @angular/cli)等。但它会给出一个错误,说它已经安装。但是这里的node_modules文件夹不会有任何angular文件夹。重新安装节点,然后重新启动我的电脑。

答案:最后我发现ng。CMD和ng。c:\ users \ jag古德温\ appdata \ roaming \npm\ here中的ps1文件仍然存在(在npm文件夹中)。尽管我做了npm uninstall -g @angular/cli。这些文件导致ng (angular/cli)认为它仍然被安装。我删除了这些文件,然后npm install -g @angular/cli@8.3.29(我需要的版本),然后我删除了我的项目node_modules,然后运行npm install,现在可以使用ng serve运行我的angular项目了。

C: \ Users \ JaGoodwin \ AppData \我办手机漫游npm喝

通过文件夹搜索%APPDATA%在你的windows搜索栏中找到这个。