'Node MODULE_NOT_FOUND

I just upgraded to node version 9.0.0 and am now getting this error in the command line when trying to use npm install

npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'internal/util/types'

I'm using:

  • OSX 10.10.5
  • Node version 9.0.0
  • NPM version 5.5.1

Extra information: I am also trying to do this with a Laravel 5.5 project. This is how I update my version of node: How do I update Node.js?



Solution 1:[1]

run

rm -rf /usr/local/lib/node_modules/npm 

and then re-install Node.js will work in most cases

Solution 2:[2]

Leaving this here for anyone using the n nodejs version manager:

$ n 6.12.0 # Go back to a stable release
$ npm install -g npm@latest # Update npm to latest
$ n lts # Get 8.9.1
$ npm install #Should work now.

The MODULE_NOT_FOUND error seems to happen when changing between node versions and some files are possibly still being cached. I am not sure exactly but the above sequence of commands work for me.

Solution 3:[3]

When I first got this, I solved just running "npm install" again to make sure everything was installed.

Solution 4:[4]

I got similar error also on Windows 8 after I have just upgraded node js. First: how I ran into the issue then the solution that worked for me.

How I ran to the issue: When I did npm --version and node --version I discovered that I wass running npm v3.x and node 5.x. So I went to nodejs.org site from where I downloaded node-v8.11.3-x64.msi. After installing the msi package I confirmed that my nodejs version was now v8.11.3 via node --version command.

Then, when I ran "npm install http-server" (w/o the quotes) that's when I got the issue:

npm ERR! node v8.11.3 npm ERR! npm v3.5.3 npm ERR! code MODULE_NOT_FOUND

My resolution: I did some research including on the internet and found out that the npm version pointed to in my path was the one in my roaming profile C:\Users[myname.hostname]\AppData\Roaming\npm. In other words, the npm being used is not the one in the updated package I have just installed which is located in C:\Program Files\nodejs.

The resolution was to delete npm and npm-cache in the roaming folder. Note, I used cygwin as I was not able to delete these folders via Windows cmd prompt. With cygwin, I navigated to

cd "C:\Users[myname.hostname]\AppData\Roaming"

Then I removed the aforementioned folders like so

rm -rf npm-cache rm -rf npm

After that, I opened a new Windows cmd prompt and was able to now successfully install http-server like so:

npm install http-server

Hope this works for you.

Solution 5:[5]

If all the above solutions doesn’t work check for any blank spaces in your folder/file where you copied the path

Solution 6:[6]

If you are using libraries make sure to install everything with npm or yarn before starting. And in cases of you files if you are going to use them make sure to do the export.module thing everytime.

Solution 7:[7]

If when you are using React And getting this error message. You can use this ,

NPM

npm install @reduxjs/toolkit

Yarn

yarn add @reduxjs/toolkit

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wrangler
Solution 2 Jack Vial
Solution 3 Fernando Soares
Solution 4 Adams
Solution 5 Rishi Tawde
Solution 6 noman
Solution 7 Jakub Kurdziel