Error “Cannot find module 'npmlog'” after “npm update -g”

前端 未结 9 1231
轻奢々
轻奢々 2020-12-20 11:35

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:



        
相关标签:
9条回答
  • 2020-12-20 11:57

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

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

    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

    0 讨论(0)
  • 2020-12-20 11:57

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

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

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

    hash -r 
    

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

    brew update
    
    brew reinstall node
    
    brew link --overwrite node
    

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

    export PATH="/usr/local/bin:$PATH"
    
    0 讨论(0)
  • 2020-12-20 12:06

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

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

    • Roll back to the previous node version which npm didn't be updated. For example, nvm use iojs
    • cd to where npm installed, for example, cd /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm and reinstall those packages like rm -rf node_modules/init-package-json && npm install init-package-json etc.
    0 讨论(0)
提交回复
热议问题