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

其他回答

对我来说,这发生在我在全球安装纱线之后。 为了解决这个问题,使用yarn安装npm。

yarn global add npm

在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.

只需卸载node js,然后使用nvm重新安装。你的问题会解决的。我是debian 10的用户。

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

执行命令后。关闭终端并重新打开,然后运行此命令安装node js的最新版本。

nvm install v14.15.5

现在输入node -v进行检查

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

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

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

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

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

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