Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Module not found for react/jsx-runtime in a component library

ErrorModule not found: Error: Can't resolve 'react/jsx-runtime'

Short answer

react/jsx-runtime is the entry point your compiler imports when it uses the new JSX transform. The error means that entry is not available to the build: either React is too old to ship it, or the bundler cannot resolve it. Upgrade React, or list it as external in Rollup.

  • Applies to React 19, Rollup 4, Babel 7.9+, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the React version that the failing package actually resolves. The new transform needs React 16.14, 17 or newer.

    npm ls react
  2. 2Match what you see, then jump to its fix

    1. 1npm ls react shows a version below 16.14.0, or two different React versionsThe installed React is older than the new JSX transform supportsFix
    2. 2The build cannot find react/jsx-runtime although React is installed, or it is bundled into your library outputRollup cannot resolve the import, so it is neither bundled nor externalFix

What does the error look like?

  • Module not found: Error: Can't resolve 'react/jsx-runtime'
  • Can't resolve 'react/jsx-runtime'

Cause 1 of 2

The installed React is older than the new JSX transform supports

1Check

The new transform needs React 17 or newer, or the backported 16.14.0 and 15.7.0 releases. Older React has no react/jsx-runtime to import.

npm ls react

2Fix

Upgrade React and react-dom, or, if you cannot upgrade, tell Babel to use the classic transform, which is still supported.

npm install react@latest react-dom@latest

// or in the Babel preset options
["@babel/preset-react", { "runtime": "classic" }]

3Verify

Reinstall and run the build or Storybook again.

npm ls react && npm run build

Confirmed by legacy.reactjs.org

Did this fix it?

Cause 2 of 2

Rollup cannot resolve the import, so it is neither bundled nor external

1Check

Rollup treats imports it cannot resolve as external, and a bare import is only resolved to node_modules when a plugin like node-resolve is used. Libraries should not bundle React at all.

grep -n -E "external|nodeResolve|node-resolve" rollup.config.*

2Fix

List react and the exact import id react/jsx-runtime as external, and keep react as a peer dependency of the library.

// rollup.config.js
export default {
  // ...
  external: ['react', 'react-dom', 'react/jsx-runtime'],
};

3Verify

Run the build and check the output keeps the import as an import.

npx rollup -c
grep -n "react/jsx-runtime" dist/*.js

Confirmed by rollupjs.org

Did this fix it?

How do I stop it coming back?

  • Declare react and react-dom as peerDependencies in a component library, and as devDependencies for local work.
  • Keep one version of React in the workspace so the library and the app resolve the same package.
  • Add every JSX-related import id (react/jsx-runtime) to external when you hand-write the list.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.