Skip to content

fix: support React 16 and 17 under strict ES module resolution - #1378

Merged
dangreen merged 1 commit into
masterfrom
fix/react-jsx-runtime
Nov 30, 2026
Merged

dangreen merged 1 commit into
masterfrom
fix/react-jsx-runtime

Conversation

@dangreen

Copy link
Copy Markdown
Collaborator

Fixes #1319.

The package imports react/jsx-runtime without a file extension. React 16 and 17 have no exports field, 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 through require().

Changes

  • src/chart.ts and src/typedCharts.ts create their elements with createElement instead of JSX, so the build imports only react and chart.js.
  • These files are .ts instead of .tsx. TypeScript does not parse JSX in .ts files, so the JSX runtime cannot come back by accident.
  • The props table of the website reads the renamed files.

Checked locally

The build was packed and installed from a tarball next to React from npm.

Scenario React Before After
webpack 5 16.8.0, 17.0.2 Can't resolve 'react/jsx-runtime' compiles
Node.js ESM import and require() 16.14.0, 17.0.2 ERR_MODULE_NOT_FOUND works, server rendering included
Node.js ESM import and require() 16.13.1 not checked works, server rendering included
Node.js ESM import and require() 18.3.1, 19 works works
  • Unit tests (60), types and lint pass.
  • size-limit: every entry is 13 to 22 B smaller, for example Chart goes from 582 B to 560 B. The limits stay.
  • The website build has the same props tables.

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 forwardRef and useRef as well as createElement. Bundlers handle these versions.

🤖 Generated with Claude Code

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

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.97%. Comparing base (c65365d) to head (c7246aa).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dangreen
dangreen marked this pull request as ready for review November 30, 2026 22:13
@dangreen
dangreen merged commit 094fa63 into master Nov 30, 2026
11 checks passed
@dangreen
dangreen deleted the fix/react-jsx-runtime branch November 30, 2026 22:13
@github-actions github-actions Bot mentioned this pull request Nov 30, 2026
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.

[Bug]: Cannot find module 'node_modules/react/jsx-runtime

1 participant