Webpack warns that React was not found in the react package
export 'React' (imported as 'React') was not found in 'react'Short answer
This happens when the code writes import { React } from 'react'. The react package has no export named React, so the bundler cannot find it. Import the default or the whole namespace instead, or better, enable the automatic JSX runtime and remove the React import from files that only use JSX.
Fix it fast
1Find out which cause you have
Find every import that pulls React in braces.
grep -rn "{ *React" src/2Match what you see, then jump to its fix
What does the error look like?
export 'React' (imported as 'React') was not found in 'react'
Cause 1 of 2
React is imported as a named export
1Check
React's guide says a named export must be imported with braces and a matching name, and a default export without braces. React's JSX transform article shows named imports only for things such as hooks, and a namespace import written as import * as React. The word React itself is not a named export of the package.
grep -rn "import {.*React.*} from 'react'" src/2Fix
Use the default or namespace import, and keep braces for hooks and other real exports.
import * as React from 'react';
import { useState } from 'react';3Verify
Run the build; the warning for that file is gone.
npm run buildConfirmed by legacy.reactjs.org
Cause 2 of 2
The import was added to satisfy the old JSX transform
1Check
With the classic runtime, JSX becomes React.createElement calls, so React must be in scope. The new transform inserts its own import from react/jsx-runtime. It is supported by Babel 7.9 and later, TypeScript 4.1 and later, and Create React App 4 and Next.js 9.5.3 and later.
grep -n "runtime" babel.config.json .babelrc 2>/dev/null2Fix
Turn on the automatic runtime in Babel, then run the codemod that removes unused React imports.
// babel.config.json
{ "presets": [["@babel/preset-react", { "runtime": "automatic" }]] }
# remove unneeded imports
npx react-codemod update-react-imports3Verify
Build again and check that files with only JSX no longer need an import.
npm run buildConfirmed by legacy.reactjs.org
How do I stop it coming back?
- Import only hooks and APIs you use, by name; leave JSX files without a React import.
- Turn off react/react-in-jsx-scope in ESLint when the automatic runtime is on.
- Run the build in CI so import warnings are seen before release.
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.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fixWeb apps
TypeScript rejects MUI Data Grid columns that set a type
A TypeScript error inside a column's renderCell callback
A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.
2 causes, each with a fixWeb apps
The renderInput prop stopped working on the MUI X DatePicker
The custom TextField (variant, size, helperText) is ignored
renderInput was removed from the MUI X date pickers in version 6.
3 causes, each with a fix