Module not found for react/jsx-runtime in a component library
Module 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.
Fix it fast
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 react2Match what you see, then jump to its fix
- 1
npm 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
The 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
- 1
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 react2Fix
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 buildConfirmed by legacy.reactjs.org
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/*.jsConfirmed by rollupjs.org
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix