createRoot from react-dom/client cannot be imported after upgrading to React 18
TypeScript cannot find the module react-dom/clientShort answer
createRoot only exists in react-dom 18 and newer, and it is imported from react-dom/client, not react-dom. Check that react and react-dom are both on 18, switch the import, and update @types/react and @types/react-dom so TypeScript knows the new entry point.
Fix it fast
1Find out which cause you have
Print the installed versions of both packages.
npm ls react react-dom @types/react @types/react-dom2Match what you see, then jump to its fix
- 1
npm ls shows react 18 but react-dom 17, or the reversereact-dom is still on an old versionFix - 2
React 18 logs an error and runs in React 17 modeThe app still uses ReactDOM.renderFix - 3
TypeScript cannot find types for react-dom/client, or children errors appear on componentsThe TypeScript type packages are oldFix
- 1
What does the error look like?
TypeScript cannot find the module react-dom/clientcreateRoot cannot be imported from react-domThe app still runs in React 17 mode after upgrading
Cause 1 of 3
react-dom is still on an old version
1Check
Both packages must be upgraded together.
npm ls react react-dom2Fix
Install both again.
npm install react react-dom3Verify
npm ls shows the same major version for both.
npm ls react react-domConfirmed by react.dev
Cause 2 of 3
The app still uses ReactDOM.render
1Check
Without switching to createRoot, React 18 runs the app in React 17 mode.
grep -rn "ReactDOM.render\|from 'react-dom'" src2Fix
Import createRoot from react-dom/client and render through the root.
import { createRoot } from 'react-dom/client';
const container = document.getElementById('app');
const root = createRoot(container);
root.render(<App />);3Verify
Start the app and check that the console error is gone.
npm run devConfirmed by react.dev
Cause 3 of 3
The TypeScript type packages are old
1Check
The type packages must be updated along with React. In the newer types, children is no longer implied and must be declared in props.
npm ls @types/react @types/react-dom2Fix
Update both type packages, and add children to props where a component uses it. With TypeScript, getElementById returns a nullable value, so pass the container with a non-null assertion or check it first.
npm install --save-dev @types/react@latest @types/react-dom@latest
interface MyButtonProps {
color: string;
children?: React.ReactNode;
}3Verify
Run the type checker.
npx tsc --noEmitConfirmed by react.dev
How do I stop it coming back?
- Upgrade react, react-dom and both type packages in one commit.
- Run the upgrade guide's codemods where it offers them.
- Check that libraries support your React version before upgrading.
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