DEV Community

Cover image for ndoe-js-cannot-find-module-error-solution or node:internal/modules/cjs/loader:936 throw err; ^(Solution)
Osman Forhad
Osman Forhad

Posted on • Updated on

ndoe-js-cannot-find-module-error-solution or node:internal/modules/cjs/loader:936 throw err; ^(Solution)

trying to run node js project which is develop in express js and other necessary library. after writing code when i decide to run the project then i wrote the command npm start and alternatively nodemon command. its show me an error which is below screenshot:

node:internal/modules/cjs/loader:936<br>
  throw err;

after this happening i was thinking and search why this is happen and why terminal show me node:internal/modules/cjs/loader:936
throw err;
^

after wasting few times i find out and figured the mistake which is done by me. so i decide to share this with all of you guys (the internet people)
.
so what was the mistake did by me: it was a case of trying to run the file in node from the wrong location.
do you understand.? if answer is no. well i explain here don't worry: here rbac is my project directory and there i have another directory which name was server and inside the server directory i have a file which name also server.js, please keep in mind this is the main point of my mistake.
.
to run this project i need to hit** server.js file by using npm start or nodemon*. in this case i was open my termial inside my main directory which name rbc as i mentioned in previous line and from here i tried to hit server.js file but this file is not in this location. the actual location of server.js file is inside **rbac/server/server.js *
so the terminal show me node:internal/modules/cjs/loader:936
throw err;
^

and when i realize my mistake then i just move server.js file from rbac/server/server.js to rbac/server.js
and then open terminal inside the project root and then run nodemon or npm star and now it's working fine. finally my terminal look like below screenshot and this is the actual view which i want to see.

ndoe-js-cannot-find-module-errorsolution
.
Happy Coding.
osman forhad
Full-Stack Developerđź’» (Mobile App & Web App)
developer.osmanforhad@gmail.com

Top comments (8)

Collapse
 
kalaiselviui profile image
Kalai-UI

Hii, i also done like you but its not working. i did everything deleting node modules again installed. but i dont know what is the issue. inside the ecommerce folder i have 2 folder backend and client. please give the solution
PS D:\react-projects\ecommerce-nodejs\backend> npm start

backend@1.0.0 start
nodemon index.js

[nodemon] 2.0.16
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node index.js
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'jsonwebtoken'
Require stack:

  • D:\react-projects\ecommerce-nodejs\backend\routes\verifyToken.js
  • D:\react-projects\ecommerce-nodejs\backend\routes\user.js
  • D:\react-projects\ecommerce-nodejs\backend\index.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (D:\react-projects\ecommerce-nodejs\backend\routes\verifyToken.js:1:13) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) { code: 'MODULE_NOT_FOUND', requireStack: [ 'D:\react-projects\ecommerce-nodejs\backend\routes\verifyToken.js', 'D:\react-projects\ecommerce-nodejs\backend\routes\user.js', 'D:\react-projects\ecommerce-nodejs\backend\index.js' ] } [nodemon] app crashed - waiting for file changes before starting...
Collapse
 
osmanforhad profile image
Osman Forhad

"scripts": {
"start": "nodemon script.js"
}
write your scripts like above where scripts.js is your app entry file which name could be anything as you like (app,js or server.js or scripts.js) anything

Collapse
 
divyansh1 profile image
divyansh-1

Hii
I have done the same but it still show the same error.

Collapse
 
kalaiselviui profile image
Kalai-UI

have you find out the solution??

Collapse
 
osmanforhad profile image
Osman Forhad

no need to do as like as me.. just read the article and understand what i actually i want to share to solve like this type of issues

Collapse
 
kalaiselviui profile image
Kalai-UI

please give the suggestion for this

Collapse
 
bhojraj31 profile image
Bhojraj singh shekhawat

Hii, i also done like you but its not working. i dont know what is the issue. inside the ecommerce folder i have 2 folder backend and frontend. please give the solution

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

Error: Cannot find module 'mongose'
Require stack:

  • E:\wsCube\mearn-project\Backend\Models\userModel.js
  • E:\wsCube\mearn-project\Backend\Controllers\userController.js
  • E:\wsCube\mearn-project\Backend\Routes\userRoute.js
  • E:\wsCube\mearn-project\Backend\app.js
  • E:\wsCube\mearn-project\Backend\server.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) { code: 'MODULE_NOT_FOUND', requireStack: [ 'E:\wsCube\mearn-project\Backend\Models\userModel.js', 'E:\wsCube\mearn-project\Backend\Controllers\userController.js', 'E:\wsCube\mearn-project\Backend\Routes\userRoute.js', 'E:\wsCube\mearn-project\Backend\app.js', 'E:\wsCube\mearn-project\Backend\server.js' ] } [nodemon] app crashed - waiting for file changes before starting...
Collapse
 
dnyaneshupsqode profile image
dnyaneshUpsqode

Hii
I have done the same but it still show the same error.