Add esbuild banner
for ESM+NodeJS builds, to work around "dynamic require not supported" issue
#7779
+58
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug report and failing test
Having
type: "module"
inpackage.json
along withserverDependenciesToBundle: "all"
inremix.config.js
causes a build error:Oddly, in this integration test, it appears to happen at run time (unless I'm misreading the stack trace), whereas in the description of #7467, the error appears at build time. However, the error did appear at run time in my earlier testing as well, as indicated in the AWS Lambda logs in my comment.
Bug fix
The general
Dynamic require of <pkg> not supported
issue is discussed at length in evanw/esbuild#1921, and it appears that several other projects have had to apply a workaround for this problem. I first attempted to apply this async IIFE approach, but I realized that Remix already has a similar workaround applied for the__file
and__dirname
globals, so I removed those bits.I'm not confident that this is the "right" fix (or a complete fix), but it makes the new integration test pass, and it doesn't appear to cause any other failures. It may also become irrelevant in the future if the esbuild issue is fixed, or if Remix fully moves to Vite, but I'm hoping it will at least unblock my current progress.
Closes: #7467
Tasks
Testing Strategy
Ran all the integration tests several times. Saw some flaky failures, and one not-as-flaky failure:
Confirmed that this test also fails (pretty reliably) without my changes.