Reputation: 415
I also had a similar issue with the last project I created
I have tried what was recommended here internal/modules/cjs/loader.js:582 throw err, although cannot guarantee that I did it right.
I have also tried creating an index.js file. Moving the index.js file and changing the "main" in package.json to various things.
I will include a picture so that you can see the file structure. Please help:
Error Message
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module './mail'
Require stack:
- /Users/test/Desktop/Git/Deep Technology/Deep-Technology/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/test/Desktop/Git/Deep Technology/Deep-Technology/server.js:5:18)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/test/Desktop/Git/Deep Technology/Deep-Technology/server.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/test/.npm/_logs/2020-08-16T20_38_06_132Z-debug.log
Andrews-iMac:Deep-Technology test$
Andrews-iMac:Deep-Technology test$ node run start
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module '/Users/test/Desktop/Git/Deep Technology/Deep-Technology/run'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Andrews-iMac:Deep-Technology test$ node server
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module './mail'
Require stack:
- /Users/test/Desktop/Git/Deep Technology/Deep-Technology/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/test/Desktop/Git/Deep Technology/Deep-Technology/server.js:5:18)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/test/Desktop/Git/Deep Technology/Deep-Technology/server.js'
]
}
Andrews-iMac:Deep-Technology test$ nodemon start
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node start index.js`
[nodemon] clean exit - waiting for changes before restart
^CAndrews-iMac:Deep-Technology test$
Update
Some errors were resolved, but still this node error:
node server
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module './node_modules/dotenv/types'
Require stack:
- /Users/test/Desktop/Git/Deep Technology/deep-technology/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/test/Desktop/Git/Deep Technology/deep-technology/server.js:2:1)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/test/Desktop/Git/Deep Technology/deep-technology/server.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/test/.npm/_logs/2020-08-16T21_23_44_657Z-debug.log
Andrews-iMac:Deep-Technology test$
Update, this is a completely different project, and I have exactly the same error code (968), It seems that I am consistently doing something wrong, code and file structure picture and error log below
> node server.js
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module '/Users/test/Desktop/Git/Project IA/Project-IA/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/test/.npm/_logs/2020-08-22T13_03_32_052Z-debug.log
Andrews-iMac:public test$
Upvotes: 0
Views: 3074
Reputation: 26
Error: Cannot find module '/Users/test/Desktop/Git/**`Project IA`**/Project-IA/server.js'
Another mistake is the name of the folder (/ Project IA /), it is written separated by "empty space", never, never name your project folders using 2 words separating with "empty space".
Use "_" underscore, "-", hyphen / minus, example: '/Users/test/Desktop/Git/Project_IA/Project-IA/server.js'.
The error is persisting because the file "server.js" is not in the "root" folder of the project. Move the file "server.js" to the root folder of the project, rename the folder "Project IA" to "IA-Project", or any other name you like, and the error will be solved!
I'm using google translator My language is Brazilian Portuguese
Upvotes: 1