Node MODULE_NOT_FOUND
Asked Answered
S

17

54

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?

Spaceband answered 2/11, 2017 at 19:39 Comment(2)
I got this error if i started node execution from a subdirectory instead of that directory where node_modules folder isPeople
Try using the relative path to your module by doing something like this: require("./<module.name>") when your module is in the same folder where you are importing fromCatt
T
60

run

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

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

Turmoil answered 2/11, 2017 at 19:58 Comment(3)
If you are running 'n' as Node Virtual Machine I recommend you remove all previous installed node versions after running the command given. Finally you are able to reinstall the version you prefer and works perfectly :DEpizootic
Had same issue and all I did was to run npm i on the command line, and it worked.Boles
I have logged in only to upvote you and say I ran this command them npm i then it worked. (I am using NVM to managing node version BTW).Capsize
U
11

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.

Ulrick answered 12/5, 2018 at 22:4 Comment(0)
M
8

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

Magree answered 30/7, 2020 at 3:28 Comment(1)
While this usually works, the culprit in this question is that an internal node package is missingCesta
P
5

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.

Perihelion answered 25/6, 2018 at 2:36 Comment(1)
rd /s %appdata%\npm %appdata%\npm-cacheDithyrambic
S
4

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.

Sonorous answered 20/6, 2022 at 2:36 Comment(0)
H
2

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

Honeyed answered 1/7, 2022 at 12:28 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewHyperkinesia
T
1

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

Tufted answered 24/9, 2020 at 6:11 Comment(0)
B
1

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.

Buoyancy answered 28/10, 2022 at 14:23 Comment(0)
H
1

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 &

Hartsock answered 16/11, 2022 at 9:24 Comment(0)
C
0

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.

Colonel answered 19/2, 2020 at 7:31 Comment(0)
P
0

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

Prose answered 8/6, 2022 at 16:58 Comment(0)
V
0

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.

Volsci answered 22/2, 2023 at 17:0 Comment(0)
P
0

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!

Purse answered 3/5, 2023 at 15:21 Comment(0)
S
0

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.

Suttles answered 2/9, 2023 at 17:51 Comment(0)
R
0

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
Ronen answered 24/5 at 16:20 Comment(1)
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From ReviewMolech
P
0

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.

Prudential answered 28/5 at 15:3 Comment(0)
L
-5

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
Landahl answered 11/4, 2022 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.