Support Bun by adjusting how @babel/plugin-transform-react-jsx
is imported.
#8007
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.
Changes
This brings Astro a step closer to running on Bun by working around an existing workaround done when loading
@babel/plugin-transform-react-jsx
.In Bun and some other tooling,
import
ing a CommonJS module that hasmodule.exports.__esModule
will tell the module loader/bundler to setmodule.exports.default
as the ESM default export, where without this annotation the default export will be set tomodule.exports
. Node does not do this transformation, which turns transpiled-to-cjs modules like@babel/plugin-transform-react-jsx
into{ default: { default: Function } }
, where in bun this loads as originally intended like{ default: Function }
This PR fixes the three places astro uses
.default.default
and ensures it handles the case where it may be just.default
.Our tracking issue for Astro as a whole is oven-sh/bun#3746. This PR doesn't fully close that yet, as there are some remaining stability issues in Bun (random segfaults) when using larger projects.
Testing
I have been manually testing this on the astro.build docs locally on macos with node.js v20.5.0 and a development build of bun.
Docs
This is an internal change to the codebase and has no user-facing side effects. Maybe I should've added a comment for future code readers to understand why checking both
.default.default
and.default
is necessary.