Error when loading events
Hello !
I'm creating a Discord bot with Sapphire and when I create an event, I have this error :
Error when loading '/home/desk/bot-sapphire/common/src/ticket/listeners/ready.js': Error: Dynamic require of "/home/desk/bot-sapphire/common/src/ticket/listeners/ready.js" is not supported
I'm using ESM!
Thanks
Solution:Jump to solution
Ok I undertstand ... I don't use .mjs extension on my file ...
But I don't understand here : https://github.com/sapphiredev/pieces/blob/main/src/lib/strategies/LoaderStrategy.ts#L73
How does it work ? If I use ESM, we should use import() instead of require(), no ?...
GitHub
pieces/src/lib/strategies/LoaderStrategy.ts at main · sapphiredev/p...
Piece loader for @sapphire/framework. Contribute to sapphiredev/pieces development by creating an account on GitHub.
6 Replies
Show code please.
My new SapphireClient in a different npm workspace:
My index.js in another npm workspace (my bot) :
My ready event:
Full logs:
I think it's because I'm using npm package
My MCSapphireClient is in the package3, my bot in the package1 and the dependency in node_modules, on the root of the project
Solution
Ok I undertstand ... I don't use .mjs extension on my file ...
But I don't understand here : https://github.com/sapphiredev/pieces/blob/main/src/lib/strategies/LoaderStrategy.ts#L73
How does it work ? If I use ESM, we should use import() instead of require(), no ?
GitHub
pieces/src/lib/strategies/LoaderStrategy.ts at main · sapphiredev/p...
Piece loader for @sapphire/framework. Contribute to sapphiredev/pieces development by creating an account on GitHub.
Why does it work ?
Can you please put all your code on GitHub? Your setup is making things very complex with the whole multiple packages setup. I hope you have a good reason for that because otherwise you're overcomplicating for no good reason.
The problem's already been solved! It's because I was using the .js extension and not .mjs. And I didn't know you could require a .js file with ESM. It's all a bit new, so I'm trying to learn as I go!
It's because I'd like to make 3 different bots with common components
So I have 4 npm workspaces: 3 for a bot and 1 for the common components