So, I’m facing a problem with my Discord.JS V.14 Bot. I use Render as a Hoster. I have a repository of my bot on GitHub and I linked it to Render but when I try to run it (Install Command: npm install & Start Command: node app.js), it returns this error:
==> Starting service with 'node app.js'
internal/modules/cjs/loader.js:888
throw err;
^
Error: Cannot find module 'node:events'
Require stack:
- /opt/render/project/src/node_modules/discord.js/src/client/BaseClient.js
- /opt/render/project/src/node_modules/discord.js/src/index.js
- /opt/render/project/src/index.js
- /opt/render/project/src/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
at Function.Module._load (internal/modules/cjs/loader.js:730:27)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/opt/render/project/src/node_modules/discord.js/src/client/BaseClient.js:3:22)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/opt/render/project/src/node_modules/discord.js/src/client/BaseClient.js',
'/opt/render/project/src/node_modules/discord.js/src/index.js',
'/opt/render/project/src/index.js',
'/opt/render/project/src/app.js'
]
}
App.js
File:
// import required modules
const express = require('express');
const bodyParser = require('body-parser');
const config = require('./config.json');
const startServer = require('./index.js');
console.log(startServer); // make sure that startServer is imported correctly
// create an instance of express
const app = express();
// use body-parser middleware
app.use(bodyParser.json());
// define routes
app.get('/', (req, res) => {
res.send('Hello, world!');
});
// start the server
const PORT = process.env.PORT || config.port;
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});
This happens only when I include this line of code here: const startServer = require('./index.js');
. When I remove it, the console does not return any error and it logs this:
==> Starting service with 'node app.js'
Server started on port 3000
But it doesn’t start the index.js
file so the rest of the bot remains deactivated! I need a way to launch the app.js and index.js without returning any errors. Thanks in advance.