user3325126
user3325126

Reputation: 1384

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:

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?

Upvotes: 55

Views: 384611

Answers (17)

Gabriel Arghire
Gabriel Arghire

Reputation: 2370

Pay attention to ../src/my-file vs src/my-file

This one was a bit harder to catch. On one device I was using Node v20 which allows for the imports of src/my-file, but on another device I was using Node v18 which only allows imports of ../src/my-file.

I renamed the imports and the error was gone.

If you are using an older version than Node v20, you need to check your imports.

Upvotes: 0

VikashVox
VikashVox

Reputation: 1

anybody have solution of this kind of error , i already reinstall node.js

enter code here
enter code here



v22.2.0

C:\Users\Vikash\Desktop\checkdemo\Angular>npx -v
node:internal/modules/cjs/loader:1189
  throw err;
  ^

Error: Cannot find module './cli/validate-engines.js'
Require stack:
- C:\Users\Vikash\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\Vikash\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1186:15)
    at Module._load (node:internal/modules/cjs/loader:1012:27)
    at Module.require (node:internal/modules/cjs/loader:1271:19)
    at require (node:internal/modules/helpers:123:16)
    at Object.<anonymous> (C:\Users\Vikash\AppData\Roaming\npm\node_modules\npm\lib\cli.js:1:25)
    at Module._compile (node:internal/modules/cjs/loader:1434:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1518:10)
    at Module.load (node:internal/modules/cjs/loader:1249:32)
    at Module._load (node:internal/modules/cjs/loader:1065:12)
    at Module.require (node:internal/modules/cjs/loader:1271:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Vikash\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
    'C:\\Users\\Vikash\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npx-cli.js'
  ]
}

Node.js v22.2.0

Upvotes: 0

nk47
nk47

Reputation: 1

I had the same issue and then I realized it was a silly mistake. I had created a separate index.js file in the root directory of my project which I should have created inside a subdirectory. So make sure of the directory/path you're in and then run the server accordingly.

Upvotes: 0

SparkItUp
SparkItUp

Reputation: 21

I had the same kind of error. The problem for me was that I didn't cd into the right directory. There was a subfolder inside the project. So, always check out if you are in the right directory before running your server.

Hope this helps!

Upvotes: 0

Henrique Ribeiro
Henrique Ribeiro

Reputation: 1

The MODULE_NOT_FOUND error happened to me and even running npm install the error persisted.

Try to do this For me, what worked was deleting the node_modules folder

rm -r -f node_modules/

After that, run the command to install the package.json dependencies

npm install

What happened to me was that when I ran npm install for the first time I had a very low internet connection and therefore I believe that the packages from package.json were not downloaded correctly and due to that the MODULE_NOT_FOUND error occurred. The funny thing is that just running the npm install command has no effect because it understands that the package is already there but it isn't. Similar as a corrupted data. In my case the npm update was without effect too.

Upvotes: 0

venky royal
venky royal

Reputation: 2250

Haa well, I have spent two days on this and have done everything I can to fix this issue even tried resetting the system but none of them reloved the issue. And accidentally found out what was causing this issue, it is because of & in my parent folder name. File hierarchy R&D>remix>blog, When I was trying to run the blog server it was throwing module not found, require stack error.

 code: ←[32m'MODULE_NOT_FOUND'←[39m,

requireStack: []

Solution: I have changed the parent folder name to RnD and it fixed the issue. If the file name contains any special characters(even parent folders) try updating it. In my case, it is &

Upvotes: 1

Y.S.
Y.S.

Reputation: 317

Make sure you are inside the project folder.

Rename the folder "node_modules" to any other name (for example: node_modules_old).

Run command: "npm i" (the command will build new the folder node_modules).

Try running your program again.

If the problem is resolved and your program is running correct, delete the old folder node_modules.

Upvotes: 1

Wa.is
Wa.is

Reputation: 29

I founded this problem too, so I found that I have imported wrong module instead of express module I had imported router module after I had replaced this two my code work as well

Upvotes: 2

hussam alhunaiti
hussam alhunaiti

Reputation: 319

For me it was package installation issue, so I just write,

npm i or npm install in the root of the application.

to open the terminal in the root of the application, if you're using VS-code right click on the package.json and click on Open in integrated terminal.

Upvotes: 4

Logic
Logic

Reputation: 31

If you are working with Local modules then don't have node_modules. All things go well in a easy way. But if you want to work with both local and node_modules then use .mjs (extension) - For modules .cjs (extension) - For common scripts which you want to run with node in which you can use require statements like

var http = require('http');
var fs = require('fs');

but if using .js extension then use

import http from "http"
import fs from "fs"

And also your package.json for type

Upvotes: 0

Ajith S Nair
Ajith S Nair

Reputation: 11

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

Upvotes: -5

Rishi Tawde
Rishi Tawde

Reputation: 21

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

Upvotes: 1

Fernando Soares
Fernando Soares

Reputation: 159

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

Upvotes: 8

noman
noman

Reputation: 1

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.

Upvotes: 0

Adams
Adams

Reputation: 79

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.

Upvotes: 5

Jack Vial
Jack Vial

Reputation: 2474

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.

Upvotes: 11

wrangler
wrangler

Reputation: 3576

run

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

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

Upvotes: 60

Related Questions