Error with Npm (Cannot Find Module 'Semver')

I had npm and nodejs working fine. I didn't mess around with for a few months as I was working with something else. Today I come back to check some projects, and when I ran "npm run dev" it gave me some warnings to update nodejs, but it worked.

Regardless I said "fine" and updated nodejs. After I update it, I run npm run dev, and it doesn't work.

I tried every solution I could find, purged, installed, uninstalled, installed, the works. It still remains with the error, even just running "npm -v" shows the error.

Full error:

    internal/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:690: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: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 version of nodejs I got installed is: v10.15.2

(By the way, I did try to install an older version, but everytime I did it I ended up with 10.15.2 regardless, no clue why that is either..)

I have no idea what to do here... Thanks in advance!

I had the same error. npm uninstall npm -g, rm -rf node_modules didn't help me, because when I tried I was getting Error: Cannot find module 'semver'. And Can solved my problem with these steps (this will delete other global modules you may be using):

LPB_Tandn_IT:~ tannetto$ rm -rf /usr/local/lib/node_modules
LPB_Tandn_IT:~ tannetto$ rm -rf ~/.npm
LPB_Tandn_IT:~ tannetto$ brew uninstall --force node
LPB_Tandn_IT:~ tannetto$ brew install node

Hope this will help those who are getting a similar problem.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest