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

其他回答

我终于明白了!是的,您必须卸载/删除所有文件并重新安装。但是有些文件路径太长,无法在卸载过程中删除。Node中的文件路径太长,可能无法删除。您必须重命名文件路径。

卸载节点后,使用命令提示符,导航到…\Appdata\roaming\(使用错误消息中的路径)。尝试用del npm删除该文件夹。然后,如果它不允许您删除文件夹,那么在下一个错误消息中开始将文件路径中的文件夹重命名为“a”或其他短名称。您可能必须对路径上的多个文件夹执行此操作。然后你就可以删除了!然后重新安装节点,它应该工作。

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

yarn global add npm

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

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

重新开始。

brew uninstall --force node
brew install node