New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Cannot find module when running with esbuild #7032
Comments
Another possible solution:
|
We'll most likely just revert the dynamic import thing, too bothersome to keep up and has only given us problems. What once was "simple", turned out to be extremely complex and complicated. |
hi following up here i recently migrated my aws lambda to use esbuild as well and discord.js seems to be breaking not sure if it's related to this issue or if you would like a new issue:
|
Hey @xrzhuang , I seem to have the same issue building with ESBuild. Did you ever figure out the cause? |
@rumblefrog no bruh i talked to a bunch of the engineers at discord and they told me to workaround instead. i did something weird where the specific fargate task using the lib isn't bundling with esbuild. i know it's whack |
Hm alright, yeah it's not ideal. I worked around it with setting packages external and archiving my node_modules directory to ship with the bundle. |
jesus im so sorry lmao |
@rumblefrog what version of d.js are you using? |
I'm currently on d.js 14.8.0 This is my esbuild config if it helps. import { build, analyzeMetafile } from 'esbuild';
async function main() {
const result = await build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'build/index.js',
platform: 'node',
target: ['node18'],
sourcemap: 'inline',
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
legalComments: 'none',
metafile: true,
alias: {
'@': './src',
},
});
console.log(await analyzeMetafile(result.metafile));
}
main(); |
It seems like you need to specify d.js relies on some class names, but your bundler is trying to minify the code, changing |
Oh, thank you, @nrauschcom , that seems to have worked! |
I'm locking this issue since the issues you mentioned are a completely different one. Feel free to open a new issue if you encounter an issue, I'll be locking this one since it was resolved over a year ago. |
Issue description
I'm using esbuild to bundle my code, along with a dependency on discord.js, before deploying it to AWS Lambda.
https://esbuild.github.io/
Read this comment on why bundling is important for some use cases other than Web Development. (thanks @nrauschcom)
It fails due to the imports in
src/client/websocket/handlers/index.js
which are generated fromConstants.WSEvents
. If that is fixed or commented out, then it fails due to the imports inActionsManager.js
which are generated from a directory listing.How to reproduce
src/client/websocket/handlers/index.js
:Workaround
discord.js can be marked as external when using esbuild which means it isn't included in the bundle and discord.js along with all of its direct and transitive dependencies must be copied across from the node_modules directory instead. It is possible to have a script do this, but of course it would nicer if discord.js worked out of the box.
https://esbuild.github.io/api/#non-analyzable-imports
History
Related to issues #6680 and #6681.
PR #6102 changed
ActionsManager.js
to generate the imports from a directory listing, unintentionally breaking bundlers (it was intended as a refactor).PR #6682 proposed to revert
ActionsManager.js
to use manual imports, but was closed without merging due to maintainability concerns.PR #6709 fixed this issue for Webpack by making use of
require.context
, but not for other bundlers such as esbuild.Possible solutions
esbuild requires the import paths to be string literals. This would make discord.js compatible with both esbuild and Webpack.
Either:
src/client/websocket/handlers/index.js
andActionsManager.js
to use manual imports.OR
With either solution, a check would be added to make sure that every entry in
Constants.WSEvents
has an associated event handler.I'm happy to prepare a PR.
Code sample
discord.js version
13.3.1
Node.js version
16.13.0
Operating system
macOS Big Sur
Priority this issue should have
Medium (should be fixed soon)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
GUILDS
I have tested this issue on a development release
802a5ac
The text was updated successfully, but these errors were encountered: