Skip to content
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

fix(react): Fix React jsx runtime import for esm #12740

Merged
merged 2 commits into from
Jul 3, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Jul 3, 2024

Fixes #12608

Sucrase injects a "react/jsx-runtime" import, however, ESM requires this to end in .js because the react package doesn't have an exports field.

With this PR we rewrite the import to "react/jsx-runtime.js" for our ESM output.

I tried importing running require.resolve("react/jsx-runtime.js") with node and it crashed so we likely shouldn't do it for CJS.

Verified

This commit was signed with the committer’s verified signature.
lforst Luca Forstner
@lforst lforst requested a review from andreiborza July 3, 2024 12:55
Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@lforst lforst merged commit 071adae into develop Jul 3, 2024
83 of 84 checks passed
@lforst lforst deleted the lforst-fix-react-jsx-runtime-import-for-esm branch July 3, 2024 15:15
@alexandersorokin
Copy link

alexandersorokin commented Jul 4, 2024

It's look like this MR should break compatibility with react@18. js extension is only need if there are no an exports field in package.json or that field contains js extension.

But react@18 does have exports field without js extension. See: https://www.npmjs.com/package/react?activeTab=code
image

Only react@17 doesn't have exports field.

andreiborza added a commit that referenced this pull request Jul 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…g react 17 (#12775)

Undoes some of the changes in
#12204 and
#12740 to fix
#12608.
andreiborza added a commit that referenced this pull request Jul 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Adds a react 17 test app so we can hopefully catch breaking react 17, as
we did recently
(#12608) with
#12204 and
#12740.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't resolve 'react/jsx-runtime' in xxx/node_modules/@sentry/react/esm
3 participants