node.js “npm update -g”后出现错误“找不到模块‘npmlog’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34702617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:45:17  来源:igfitidea点击:

Error "Cannot find module 'npmlog'" after "npm update -g"

node.jsnpmnvm

提问by peflorencio

I have NVM 0.30.1 and used it to install node.js v5.4.0 (with NPM 3.5.4) on Fedora 22. When I run npm update -g, I receive the following warnings:

我有 NVM 0.30.1 并用它在 Fedora 22 上安装 node.js v5.4.0(带有 NPM 3.5.4)。当我运行时npm update -g,我收到以下警告:

npm WARN EBUNDLEOVERRIDE Replacing bundled npm > init-package-json with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > node-gyp with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npm-install-checks with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npmlog with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > read-package-json with new installed version

And after that, when I run npm I get this error:

之后,当我运行 npm 时,出现此错误:

module.js:328
    throw err;
    ^

Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:20:13
    at Object.<anonymous> (/home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:76:3)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)

Does anyone know what it is and how to solve it?

有谁知道它是什么以及如何解决它?

Thanks

谢谢

采纳答案by peflorencio

Thanks for the answers. It was a bugand it has already been fixed in Node v5.4.1. Now it's working as usual.

感谢您的回答。这是一个错误,它已在 Node v5.4.1 中修复。现在它像往常一样工作。

回答by Alan H.

What fixed this for me was

为我解决这个问题的是

sudo rm -rf /usr/local/lib/node_modules/

and then re-installing node (with npm).

然后重新安装节点(使用 npm)。

回答by motou

It looks like npm update -gcannot update npm to the newest version. I solve the problem by updating npm installation manually.

看起来npm update -g无法将 npm 更新到最新版本。我通过手动更新 npm 安装解决了这个问题。

  1. Install/ reinstall node to get the bundled npm
  2. run npm install -g [email protected]to update the global npm installation
  3. now npm update -gshould work
  1. 安装/重新安装节点以获取捆绑的 npm
  2. 运行npm install -g [email protected]以更新全局 npm 安装
  3. 现在npm update -g应该工作

回答by Saiyaff Farouk

I have faced the same issue in my Windows 10 PC. After looking into solutions, since i couldn't find the exact solution for the issue i was facing Cannot find module 'npmlog'I just uninstalled the node js and then, deleted both 'npm' and 'npm-cache' in "C:\Users\YourPCName\AppData\Roaming"

我在 Windows 10 PC 中遇到了同样的问题。在研究解决方案后,由于我找不到我面临的问题的确切解决方案 无法找到模块“npmlog”,我只是卸载了节点 js,然后在“C: \Users\YourPCName\AppData\Roaming”

Then, i downloaded the latest version of node from Node JS Website

然后,我从Node JS 网站下载了最新版本的 node

And, installed node js

并且,安装了节点js

After that i checked with the path in environment variables.

之后我检查了环境变量中的路径。

Finally run the command prompt 'run as administrator' and npm install npm -g

最后运行命令提示符“以管理员身份运行”和npm install npm -g

Checking your version will show the latest version. 'npm -v'

检查您的版本将显示最新版本。'npm -v'

I got the latest version - v3.10.9

我得到了最新版本 - v3.10.9

Try this. this should work.

尝试这个。这应该有效。

回答by hithere

If people with linux are facing the problem, here is the solution:

如果使用 linux 的人遇到问题,这里是解决方案:

As of the date of this post, the NPM version packaged with Nodejs doesn't work. If you installed this package, run

截至本文发布之日,与 Nodejs 一起打包的 NPM 版本不起作用。如果你安装了这个包,运行

sudo rm -rf /usr/local/bin/npm
sudo apt-get install node
sudo mv /usr/bin/npm /usr/local/bin/npm

New version should be 3.10.8 and the old error gone

新版本应该是 3.10.8 并且旧的错误消失了

回答by Yujun Wu

init-package-json, node-gyp, npm-install-checks, npmlog, read-package-json didn't installed correctly. Not sure why though.

init-package-json、node-gyp、npm-install-checks、npmlog、read-package-json 未正确安装。不知道为什么。

Didn't find the root cause for the issue but I used the hacky way to install the packages above for now:

没有找到问题的根本原因,但我现在使用 hacky 方式来安装上面的软件包:

  • Roll back to the previous node version which npm didn't be updated. For example, nvm use iojs
  • cdto where npm installed, for example, cd /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npmand reinstall those packages like rm -rf node_modules/init-package-json && npm install init-package-jsonetc.
  • 回滚到之前没有更新 npm 的节点版本。例如,nvm use iojs
  • cd例如,安装到 npm 的位置,cd /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm然后重新安装这些软件包等rm -rf node_modules/init-package-json && npm install init-package-json

回答by Fillipo Sniper

Some of the answers already answered the question, but I will still like to throw in my own idea. I encountered same issue after I was told to run npm update -g npmafter running that piece of code, the error started. I solved mine by using Node Version Manager(nvm):

一些答案已经回答了这个问题,但我仍然想提出我自己的想法。在我被告知npm update -g npm在运行那段代码后运行后,我遇到了同样的问题,错误开始了。我使用 Node Version Manager( nvm)解决了我的问题:

nvm install 8

Note:not actually 8, but to a version of your choice e.g(6,5). Writing the version number will automatically install the stable of the version specified. After the installation you should get a CLI message:

注意:实际上不是 8,而是您选择的版本,例如(6,5)。写入版本号将自动安装指定版本的稳定版。安装后,您应该会收到一条 CLI 消息:

Now using node v8.11.4 (npm v5.6.0) 

回答by Grant

If you're using a Mac, perform the following steps, to remedy (assuming you have Homebrew installed already):

如果您使用的是 Mac,请执行以下步骤以进行补救(假设您已经安装了 Homebrew):

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*

(to overcome bash: /usr/local/bin/npm: No such file or directoryerror):

(克服bash: /usr/local/bin/npm: No such file or directory错误):

hash -r 

Then go ahead with updating brew (to keep its kegs up to date) and the reinstallation process, linking is optional.

然后继续更新 brew(以使其小桶保持最新)和重新安装过程,链接是可选的。

brew update

brew reinstall node

brew link --overwrite node

At any point inbetween you can use npm -vor node -vto test whether or not you are making progress. If you have nodereturning a version, but not npmthen you will need to add your path to your environment with:

在两者之间的任何时候,您都可以使用npm -vnode -v来测试您是否正在取得进展。如果您node返回了一个版本,但没有返回,npm那么您需要将您的路径添加到您的环境中:

export PATH="/usr/local/bin:$PATH"