我不能在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)

当前回答

这个问题通常发生在node js和npm版本不兼容的时候。 在Ubuntu(我的版本是20)中修复这个问题

卸载node js和npm。 Apt移除NPM Apt删除nodejs 哪个节点(它将返回节点js文件路径) 删除节点目录 安装NVM 安装 安装节点 NVM安装,例如NVM install 8.16 上面的命令本身会安装node js和它兼容的NPM。

其他回答

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

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

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

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

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

在Windows上,再次下载Node的MSI并进行“修复”对我有用。

在MS Windows上,解决方案是删除%APPDATA%\npm并重新安装node

我得到一个错误说权限被拒绝后运行任何'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搜索栏中找到这个。

我也犯了同样的错误。npm uninstall npm -g, rm -rf node_modules没有帮助我,因为当我尝试时,我得到错误:无法找到模块'semver'。但是我用这些步骤解决了我的问题(这将删除你可能正在使用的其他全局模块):

Sudo rm -rf /usr/local/lib/node_modules Sudo rm -rf ~/.npm 酿造卸载——force节点 Brew安装节点

希望这能帮助到那些有类似问题的人。