我不能在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上,如果你想通过默认的存储库使用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中的文件路径太长,可能无法删除。您必须重命名文件路径。

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

在我的情况下,简单地重新运行brew install yarn解决了这个问题。

在WSL(所以,~Ubuntu)上,我通过apt安装了nodejs和npm,然后使用n更新Node后,我遇到了这个问题。

我可以通过完全删除apt的npm安装来解决这个问题:sudo apt purge 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

我也有这个,在昨天运行brew安装纱线后。至少,在那之前一切都很好。

我运行rm -rf node_modules并尝试重新安装,但没有npm命令工作。

最后,我采取了相当简单的步骤,通过Mac OS X的官方Node安装程序重新安装Node。

https://nodejs.org/en/download/

现在一切都好了。回到目录,运行npm install,它就完成了。