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

当前回答

实际上,它引用了以前存储的模块。

处理步骤:删除nodejs安装目录下的“npm-cache/npm”文件夹。 在windows中,它在C:/User/Username/Appdata/Roaming/npm(或npm_cache)中。 并尝试重新安装。

在任何操作系统中都是一样的。

其他回答

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

在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下安装的节点。

在Ubuntu上,如果你想通过默认的存储库使用apt来管理Node,最好同时安装nodejs和npm。

你正在使用的npm版本很有可能在某个特定的位置期望与你已经安装的Node JS版本不一致。如果只有一个版本的nodejs和一个版本的npm,并且它们都是使用默认存储库安装的,这应该可以完美地工作。

下面是我的最佳指导,让Node和npm使用Ubuntu的主要存储库工作:

sudo apt-get purge nodejs --auto-remove and sudo apt-get purge npm --auto-remove whereis node: remove all the versions of node, one at a time. Repeat until this command returns a blank after node:. sudo apt-get install nodejs node --version: should return ... no such file or directory nodejs --version: should return v1x.x.x. This is the version installed by apt. It will probably be less recent that the latest version available on the Node JS website. sudo apt-get install npm npm --version: it will use the nodejs installed by apt and work correctly.

这适用于我的Ubuntu(最新版本日期为2020年10月)

我必须首先从bash源代码中获取代码:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

这得到了更新我的库的节点的最新版本,并摆脱了'semver'错误。

在WSL(所以,~Ubuntu)上,我通过apt安装了nodejs和npm,然后使用n更新Node后,我遇到了这个问题。

我可以通过完全删除apt的npm安装来解决这个问题:sudo apt purge npm。