I get this error eventhough discord.js is installed:
module.js:550
throw err;
^
Error: Cannot find module 'discord.js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/app/index.js:1:79)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Try deleting line of this package from package.json
and install it again using console:
pnpm install discord.js
This often happen when pnpm
is not enabled for your project.
Go to your project page console and type out enable-pnpm
and it will restart the project, installing all modules and fixing the problem.
Thanks so much, it worked!
2 Likes
How do I open ge project page console?
Click on Tools > Terminal .
This will open terminal at project page. You can get dedicated terminal tab by clicking “Full Page Terminal”
Use this command if you are using node.js in your terminal or cmd in your bot folder
npm install discord.js
I didn’t install at first
1 Like
You will have to reinstall discord.js for every project or bot you make.
npm install discord.js
1 Like
@CodingLearner10, thanks for the tip!
But please do not bump threads in the future.
well, it doesnt work in my case
i have my js file in shared storage
node ~/storage/shared/stuff/hazy/hazy.js
// imports + required variables
const Discord = require('discord.js');
const client = new Discord.Client;
// basic configurations
const config = require('./config.json');
const logging_channel = config.logging_channel;
const prefix = config.prefix;
const owner_role_id = config.owner_role_id;
//bot ready event - message to log on startup
client.on('ready', () => {
console.log('Logged in as ${client.user.tag}!');
client.channels.fetch(logging_channel)
// custom log message
.then(channel => channel.send('hi, i just came online from nitins mobile phone'))
});
// custom bot status
client.on('ready', ()=> {
client.user.setActivity(`vocal percutions on whole other level`);
});
client.on("message", message => {
if (message.content.toLowerCase() === 'ping') {
message.channel.send(`${message.member} pong`)
}
})
client.login(config.token)
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'discord.js'
Require stack:
- /storage/emulated/0/stuff/hazy/hazy.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/storage/emulated/0/stuff/hazy/hazy.js:2:17)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/storage/emulated/0/stuff/hazy/hazy.js' ]
}