Can I use discord.js as an ES modules? And make use of import and export statements?

The above.
7 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
duck
duck11mo ago
yes
pie
pie11mo ago
how ahhh, wait i've just go tto use the default export alright, thank you Is there any other methods though? As that of course really does not look clean,
duck
duck11mo ago
I'm not exactly sure what you're asking
pie
pie11mo ago
sorry, really tired, and i'm not very good at explaining anyway - so i'm getting this error.
SyntaxError: Named export 'Flags' not found. The requested module 'discord.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'discord.js';
const { Client, GatewayIntentBits, EmbedBuilder, Collection, PermissionsBitField, Flags } = pkg;
SyntaxError: Named export 'Flags' not found. The requested module 'discord.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'discord.js';
const { Client, GatewayIntentBits, EmbedBuilder, Collection, PermissionsBitField, Flags } = pkg;
However, I was wondering if there's any other way of just import all discord.js as import DJS from 'discord.js' (as a default export). As I'd really like to make use of ES modules.
duck
duck11mo ago
your error comes from Flags not existing what you name the default export is entirely up to you you're also free to import specific exports using import { ... } from "discord.js" syntax
pie
pie11mo ago
ahh jeez, alright - thanks so much