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

当前回答

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

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

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

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

其他回答

我在这里也面临同样的问题。

如果在运行brew install yarn后发生这种情况,请尝试运行yarn global add npm和voilà -已修复!

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

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*

sudo apt-get purge nodejs npm
sudo apt autoremove

然后安装node和npm

别介意 安装纱。通过npm执行并行安装,从而获得更好的速度和性能

须藤易脱纱 curl - ss https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - 回显"deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list Sudo apt-get update Sudo apt-get install yarn -y

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