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

当前回答

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

yarn global add npm

其他回答

当我使用较低版本的node运行npm install时遇到了这个问题。后来当我升级到最新版本的节点并运行gulp时,它已经显示了这个错误。

为了解决这个问题,删除node_modules并重新运行npm install。然后一口气就咽下去了。

对我来说,它发生在我的项目从gulp 3升级到gulp 4的时候。 所以,当我运行“gulp watch”命令时,它抛出了同样的错误。

这可能是由于与我的全球安装的gulp版本不匹配。

因此,要么用“-g”全局标志升级gulp会有所帮助,要么我按照下面的方法进行

但是,我在我的项目中使用了“./node_modules/.bin/gulp watch”。这确保了gulp需要的所有依赖项都只取自node_modules。

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

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

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

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

只需卸载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进行检查