Npm install cannot find module 'semver'

后端 未结 26 1326
南方客
南方客 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:49

    Faced this issue when I ran npm install using a lower version of node. Then later when I upgraded to latest version of node and ran gulp, it has shown this error.

    To resolve, deleted node_modules and re-ran npm install. Then gulp ran fine.

    0 讨论(0)
  • 2020-11-29 15:50

    In my case on macOS(10.13.6), when I executed the following command

    npm install -g react-native-cli
    

    I got this error

    Error: Cannot find module 'semver'
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
        at Function.Module._load (internal/modules/cjs/loader.js:562:25)
        at Module.require (internal/modules/cjs/loader.js:690:17)
        at require (internal/modules/cjs/helpers.js:25:18)
        at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:2:14)
        at Module._compile (internal/modules/cjs/loader.js:776:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
        at Module.load (internal/modules/cjs/loader.js:653:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
        at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    

    The error got resolved after executing the command

    yarn global add npm
    

    proposed by @Ashoor

    0 讨论(0)
  • 2020-11-29 15:53

    In my case, on macOS, I fixed this by installing the latest Node and npm versions from https://nodejs.org/en/download/

    0 讨论(0)
  • 2020-11-29 15:53

    Just make sure semver is installed: npm install -g semver

    0 讨论(0)
  • 2020-11-29 15:55

    if you are in Linux server exit from the server and re ssh

    0 讨论(0)
  • 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.
    0 讨论(0)
提交回复
热议问题