2

When I use npm, I get this error. Every npm command ends up showing the following error (Ubuntu 20.04):

internal/modules/cjs/loader.js:834
  throw err;
  ^

Error: Cannot find module 'semver'
Require stack:
- /usr/share/npm/lib/utils/unsupported.js
- /usr/share/npm/bin/npm-cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:903:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/share/npm/lib/utils/unsupported.js',
    '/usr/share/npm/bin/npm-cli.js'
  ]
}

2 Answers2

2

I simply reinstalled all Node.js versions and the error is gone!

Edit: The error caused by using yarn and npm simultaneously. By removing one of them the problem should be resolved.

MAChitgarha
  • 3,728
  • 2
  • 33
  • 40
0

If you run an npm command to start your code, one of the things your code will do is to fetch the module from the require('') line in your code. However the issue is, it's fetching a module named semver but it can't find it. It likely means it isn't installed. Try running npm install semver

destroyer22719
  • 356
  • 2
  • 6