Npm install cannot find module 'semver'

后端 未结 26 1518
南方客
南方客 2020-11-29 15:29

I can\'t use npm install using the command prompt in NodeJS. I\'m getting these errors when running npm install:

module.js:339
             


        
26条回答
  •  醉酒成梦
    2020-11-29 15:56

    On Ubuntu, if you would rather manage Node through the default repositories using apt, it's best to install both nodejs and npm this way.

    It's very likely that the version of npm you are using is expecting semver in a specific place that is not aligned with the version of Node JS you have installed. If there is only one version of nodejs and only one version of npm, and they are both installed using the default repositories, this should work perfectly.

    Here is my best guidance for getting Node and npm working using the main Ubuntu repositories:

    1. sudo apt-get purge nodejs --auto-remove and sudo apt-get purge npm --auto-remove
    2. whereis node: remove all the versions of node, one at a time. Repeat until this command returns a blank after node:.
    3. sudo apt-get install nodejs
    4. node --version: should return ... no such file or directory
    5. 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.
    6. sudo apt-get install npm
    7. npm --version: it will use the nodejs installed by apt and work correctly.

提交回复
热议问题