我不能在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和npm的版本,你需要运行一个项目。

如果是这种情况,你需要通过npm install -g semver手动安装semver

其他回答

只需删除/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.

刚刚在Arch Linux 4.13.3上遇到了这个问题,我通过简单地重新安装semver解决了这个问题:

pacman -S semver

我在AWS Linux上安装时也遇到了同样的问题。我必须用sudo安装它。因此,为了解决这个问题,我遵循了本文中的第3步(确保获得最新版本的node)

https://www.hostingadvice.com/how-to/update-node-js-latest-version/

wget https://nodejs.org/dist/vx.x.x/node-vx.x.x-linux-x64.tar.xz
tar -C /home/aUser/node --strip-components 1 -xJf node-vx.x.x-linux.x64.tar.xz

但是将它安装到用户的主目录/home/ auser /node。然后将该路径添加到我的path中。

导出路径= / home /用户/节点/ bin:美元的道路

在那之后,我就可以毫无问题地进行npm安装了。

重新开始。

brew uninstall --force node
brew install node

我也遇到过同样的问题,我解决它的方法是执行

PATH="$PATH"

在终端中,问题是终端保留了旧的nodejs路径,而不是使用新的路径。