Repository navigation
fix: support React 16 and 17 under strict ES module resolution - #1378
Merged
Merged
Conversation
The package imported `react/jsx-runtime`, which Node.js and webpack 5 cannot resolve in React 16 and 17: they have no `exports` field, and React before 16.14 has no JSX runtime at all. The components create their elements with `createElement` now, and their sources are .ts files, so JSX cannot come back by accident.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1378 +/- ##
=======================================
Coverage 93.97% 93.97%
=======================================
Files 3 3
Lines 83 83
Branches 20 20
=======================================
Hits 78 78
Misses 3 3
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1319.
The package imports
react/jsx-runtimewithout a file extension. React 16 and 17 have noexportsfield, so strict ES module resolution cannot find that path. This affects Node.js and webpack 5, which resolves imports of ES module packages as fully specified. On top of that, React before 16.14 has no JSX runtime at all. With 6.0 the same resolution also applies to CommonJS projects, since they load the ES module throughrequire().Changes
src/chart.tsandsrc/typedCharts.tscreate their elements withcreateElementinstead of JSX, so the build imports onlyreactandchart.js..tsinstead of.tsx. TypeScript does not parse JSX in.tsfiles, so the JSX runtime cannot come back by accident.Checked locally
The build was packed and installed from a tarball next to React from npm.
Can't resolve 'react/jsx-runtime'importandrequire()ERR_MODULE_NOT_FOUNDimportandrequire()importandrequire()Chartgoes from 582 B to 560 B. The limits stay.One limit remains, and it was there before: plain Node.js ESM without a bundler cannot take named exports from the CommonJS build of React 16.8 to 16.12. This affects
forwardRefanduseRefas well ascreateElement. Bundlers handle these versions.🤖 Generated with Claude Code