Tests print that ReactDOM.render is no longer supported in React 18
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17.Short answer
React 18 warns when anything calls ReactDOM.render and runs that tree in React 17 mode. In tests the caller is either an old React Testing Library (before 13), a render call with legacyRoot turned on, or your own test helper. Upgrade the library, remove legacyRoot, or switch your helper to createRoot.
Fix it fast
1Find out which cause you have
See which versions of React and React Testing Library are installed, and find every call to ReactDOM.render in the project.
npm ls react react-dom @testing-library/react grep -rn "ReactDOM.render\|from 'react-dom'" src2Match what you see, then jump to its fix
- 1
The warning appears in every test that calls render() from the library, and no source file calls ReactDOM.render.@testing-library/react is older than version 13Fix - 2
The library is current, but the warning shows only in the tests that pass the legacyRoot option.render() is called with legacyRoot: trueFix - 3
grep finds ReactDOM.render in src/index or in a test utils file.Your own entry file or test helper still calls ReactDOM.renderFix
- 1
What does the error look like?
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17.The current testing environment is not configured to support act(...)
Cause 1 of 3
@testing-library/react is older than version 13
1Check
Version 13 of React Testing Library added support for React 18 and dropped React 17 and earlier. Older versions render through the legacy API.
npm ls @testing-library/react2Fix
Update the library and its peer dependency @testing-library/dom.
npm install --save-dev @testing-library/react@latest @testing-library/dom@latest3Verify
Run the tests; the warning is gone.
npx jestConfirmed by github.com
Cause 2 of 3
render() is called with legacyRoot: true
1Check
The release notes say version 13 uses createRoot by default and that render(ui, { legacyRoot: true }) opts out, with console warnings because the legacy root API is deprecated in React 18.
grep -rn "legacyRoot" src2Fix
Remove the option so the default createRoot path is used.
// before
render(<App />, { legacyRoot: true });
// after
render(<App />);3Verify
Run the affected tests.
npx jest path/to/testConfirmed by github.com
Cause 3 of 3
Your own entry file or test helper still calls ReactDOM.render
1Check
React 18 deprecates ReactDOM.render: using it warns and runs the app in React 17 mode.
grep -rn "render(" src/index.js src/index.tsx src/test-utils* 2>/dev/null2Fix
Create a root with createRoot from react-dom/client and call root.render. If a test then says the environment is not configured for act(...), set the flag in your test setup file.
import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('app'));
root.render(<App />);
// test setup file, only when you use createRoot yourself in tests
globalThis.IS_REACT_ACT_ENVIRONMENT = true;3Verify
Run the tests and start the app; no React 18 warning remains.
npx jestConfirmed by react.dev
How do I stop it coming back?
- Upgrade React and @testing-library/react together, and check the library's release notes for the minimum React version.
- Keep all rendering in one test-utils file so a future API change touches one place.
- Treat console warnings in tests as failures in CI so a legacy API call does not hide.
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
createRoot from react-dom/client cannot be imported after upgrading to React 18
createRoot cannot be imported from react-dom
createRoot only exists in react-dom 18 and newer, and it is imported from react-dom/client, not react-dom.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb 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
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix