0

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:

enter image description here

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! Deep-Technology@1.0.0 start: `node server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the Deep-Technology@1.0.0 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! deep-technology@1.0.0 start: `node server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the deep-technology@1.0.0 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

enter image description here

> 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! myinfuenceradssite@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the myinfuenceradssite@1.0.0 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$ 
AndrewNeedsHelp
  • 385
  • 4
  • 15
  • 1
    You forgot to copy the error message (including stack) into your question. – CherryDT Aug 16 '20 at 21:01
  • @CherryDT thanks, added – AndrewNeedsHelp Aug 16 '20 at 21:03
  • 1
    By the way, what does the warning say in line 2? – CherryDT Aug 16 '20 at 21:03
  • 1
    The error says it cannot find the module `./mail` - and in fact, I don't see any `mail.js` file or `mail` folder in your project's directory! So I'm not sure how we can help you because you are requiring a module that doesn't exist; we don't know what is supposed to be in this module! – CherryDT Aug 16 '20 at 21:04
  • String does not match the pattern of "^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$". got this error message atm if thats what you mean – AndrewNeedsHelp Aug 16 '20 at 21:04
  • 1
    OK that's probably not related but you should fix it as well - what it says is that package names cannot have uppercase characters, so you should rename your directory and the package name to `deep-technology` instead of `Deep-Technology`. – CherryDT Aug 16 '20 at 21:05
  • what does that mean, so there so I am missing I file that I have referenced, and therefore node won't run? referring to your post about /mail – AndrewNeedsHelp Aug 16 '20 at 21:06
  • 1
    Right. If you say you want to load the module `mail` in your project but there is no such module, you cannot run your program, because how would it run the code inside this module if it doesn't exist? :) That's why it fails. According to the error message, you attempt to load this module in your `server.js` in line 5. – CherryDT Aug 16 '20 at 21:07
  • Error: Cannot find module './node_modules/dotenv/types' – AndrewNeedsHelp Aug 16 '20 at 21:32
  • 1
    It doesn't make sense to write a require path like this... `./node_modules/xyz` is never right, and you also cannot require `dotenv/types` from Javascript because it has no `index.js`, only a `index.d.ts` (a TypeScript definition file). What are you trying to do there? Please show your code and explain why you are even importing these things in the first place, otherwise it's all just guesswork. – CherryDT Aug 17 '20 at 08:38
  • @CherryDT not fully sure what you mean by: "It doesn't make sense to write a require path like this... ./node_modules/xyz". You were right on that env issue, which has now been resolved. Not sure how I keep getting the same error. Any ideas? – AndrewNeedsHelp Aug 22 '20 at 13:12
  • I thought it was because of firebase but I don't have firebase in the original project by the look of it – AndrewNeedsHelp Aug 22 '20 at 13:14

1 Answers1

1
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