Maaz Zindani

Loading the index…

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

Cannot find module react/jsx-runtime in a React build

ErrorCannot find module 'react/jsx-runtime'

Short answer

react/jsx-runtime is the file the new JSX transform imports for you. The error means your compiler is set to the automatic runtime but the installed react package does not contain that file, or is not installed. Upgrade React to a version that ships it, or switch the compiler back to the classic runtime.

  • Applies to React 19, Babel 7, webpack 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which React version is installed. The runtime file arrived with React 17, and was backported to 16.14.0.

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

    1. 1npm ls react shows 16.13 or lower, or 15.xReact is older than the version that ships jsx-runtimeFix
    2. 2npm ls react prints (empty), or the error comes from a library that expects react as a peerreact is not installed in this projectFix
    3. 3A pinned old React, and Babel set to runtime automaticYou cannot upgrade React yetFix

What does the error look like?

  • Cannot find module 'react/jsx-runtime'
  • Uncaught Error: Cannot find module 'react/jsx-runtime'

Cause 1 of 3

React is older than the version that ships jsx-runtime

1Check

The automatic runtime needs React 17 or later, or 16.14.0, 15.7.0 or 0.14.10 from their backports.

node -p "require('react/package.json').version"

2Fix

Upgrade React and react-dom together.

npm install react@latest react-dom@latest

3Verify

Confirm the file now resolves.

node -e "require.resolve('react/jsx-runtime')"

Confirmed by legacy.reactjs.org

Did this fix it?

Cause 2 of 3

react is not installed in this project

1Check

Library code compiled with the new transform imports react/jsx-runtime from your project's own node_modules.

ls node_modules/react/package.json

2Fix

Install react and react-dom in the app.

npm install react react-dom

3Verify

Rebuild the app.

npm run build

Confirmed by react.dev

Did this fix it?

Cause 3 of 3

You cannot upgrade React yet

1Check

Look at your Babel preset. The automatic runtime is opt-in, and classic is the default.

grep -rn "runtime" .babelrc babel.config.js package.json

2Fix

Set the runtime to classic, and import React in files that use JSX. Prefer the upgrade when you can.

{
  "presets": [
    ["@babel/preset-react", { "runtime": "classic" }]
  ]
}

3Verify

Rebuild.

npm run build

Confirmed by legacy.reactjs.org

Did this fix it?

How do I stop it coming back?

  • Keep react and react-dom on the same version, and update them together.
  • Set Babel's runtime on purpose so the choice is visible in the config.
  • Check that a library's peer dependency range matches the React you run.

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.