M HYPE SPLASH
// news

npm Error: Cannot find module 'semver'

By Sarah Scott

I get the following error when I try to run npm command

root@localhost:# npm --version
internal/modules/cjs/loader.js:584 throw err; ^
Error: Cannot find module 'semver' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3)
Aborted

I've tried uninstalling and re-installing npm and nodejs, but i still get the error

How can i fix this?

1 Answer

  1. I manually uninstalled node and npm:
    sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
    sudo rm -rf /usr/local/lib/node* ; sudo rm -rf /usr/local/include/node* ; sudo rm -rf /usr/local/bin/node*
    sudo apt-get purge nodejs npm
  2. I re-installed node and npm manually by downloading from Node.js:
    tar -xf node-v5.9.0-linux-x64.tar.xz sudo mv node-v5.9.0-linux-x64/bin/* /usr/local/bin/ sudo mv node-v5.9.0-linux-x64/lib/node_modules/ /usr/local/lib/
    # Verify installation: node -v ; npm -v

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy