I tried to start my discord bot via heroku and it didn't start, when i checked the logs it gave me this response
Starting...
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'Discord.js'
Require stack:
- /app/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/app/index.js:3:29)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/index.js' ]
}
To me it seems like it tries to start the index.js file through the filepath /app/index.js but the file is not located in /app/index.js but instead just /index.js and I never even entered anything about the /app filepath anywhere so I dont know why it does this
Edit: I realised that the logs didnt show anything useful ton search because I entered the logs too late and if I entered them earlier I would see more info about the error. Heres what it said earlier
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/index.js' ]
}
Process exited with status 1
State changed from up to crashed
CodePudding user response:
The issue is probably located in the package.json file because there is a field called main there which defines where your main file is located.
{
"name": "lhubot",
"version": "2.2.6",
"description": "",
"main": "index.js",
...
}
CodePudding user response:
I found a answer myself, i wrote the wrong name for discord.js in require('discord.js'). I wrote "Discord.js" instead of "discord.js". Not sure why heroku found it as a problem but it was fine when i ran it on my own computer but that was the solution for me.
