Search code examples
npmnodesnode-modulesnpm-installsemantic-versioning

Not able to run any npm command due to following error - Error: Cannot find module 'semver'


  • previously node was working properly.

  • After that as i wanted to install express & socket.io.

  • it asked for node version update.

  • i tried to update node version & i believe i forgot some command to run in updation process.

  • now it's giving following error on any npm command. even if i type only npm, that'll give error.

    m@m-Lenovo-ideapad-320-15IKB:/var/www/html/chat$ npm -v
    nternal/modules/cjs/loader.js:638
        throw err;
        ^
    
    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:692:17)
        at require (internal/modules/cjs/helpers.js:25:18)
        at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14)
        at Module._compile (internal/modules/cjs/loader.js:778:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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)
    

Solution

  • Finally it got solved, i think following process worked.

    • deleted npm module from usr folder
    • I removed npm module
    • cleared the cache
    • installed npm

    & it worked

    The mistake i was doing was not clearing the cache