"node:internal/modules/cjs/loader:1080 throw err; ^"

27.2k Views Asked by At

I'm getting the following error in the console:

node:internal/modules/cjs/loader:1080
  throw err;
  ^

Error: Cannot find module 'C:\Users\Sayan\OneDrive\Desktop\project prac\node\index.js'   
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.16.1

What should I do ?

Already tried : Delete the node_modules directory Delete the package-lock.json file Run npm install

Also tried : created a new folder and did the same

5

There are 5 best solutions below

1
Leonardo Capone On

Try with:

import * as fs from 'fs';
0
Gene Peter Delos Santos On

The error message reads: 'Cannot find module 'C:\Users\Sayan\OneDrive\Desktop\project prac\node\index.js.' This usually indicates that you are attempting to run the 'node' command from a different directory or that the file 'index.js' does not exist in the specified directory. In my case I was trying to run it on folder above my 'index.js' folder.

1
Vashu Kashyap On

This error is occurring because there is a space in path like: C:\Users\DELL\Documents\web development\nodejs\basic> Here, in the path of directory there is a space "web development" try to remove this space by rename. Or you can rename this to "web_development".

1
rahunak On

In my case it was wrong name of index file: index,js
After fixing it, the errors are gone.

0
quangdang On

I don't know What module you had installed, but in my case when I use json-server

I got same error when used json-server I had tried many way like

  • remove node_module and package.json but didn't work
  • I use json-server lastest with 1.0.0-alpha.21 So I think that I must update node and npm version but still didn't work

So I try don't use lastest 1.0.0-alpha.21 and change to "json-server": "^0.17.4" It work well In node project I do

  • npm uninstall json-server (remove package json-server)
  • npm install [email protected] (install with specify version)