facebook/react · error · Error
react-test-renderer/shallow has been removed. See https://re
Error message
react-test-renderer/shallow has been removed. See https://react.dev/warnings/react-test-renderer.
What it means
react-test-renderer was deprecated and its shallow rendering entry point was removed in modern React versions. The npm/shallow.js stub exists only to throw immediately when the removed submodule is imported, pointing users at the deprecation notice.
Source
Thrown at packages/react-test-renderer/npm/shallow.js:4
'use strict';
function ReactShallowRenderer() {
throw new Error(
'react-test-renderer/shallow has been removed. See https://react.dev/warnings/react-test-renderer.'
);
}
module.exports = ReactShallowRenderer;
View on GitHub (pinned to eafeac097b)
Solutions
- Replace shallow-render assertions with the standalone community package react-shallow-renderer
- Rewrite the tests with react-test-renderer's create() (full render) or @testing-library/react
- Pin React 18 if the codebase cannot be migrated yet, as a temporary measure
Example fix
// before
import ShallowRenderer from 'react-test-renderer/shallow';
const renderer = new ShallowRenderer();
renderer.render(<MyComponent prop={1} />);
// after
import ShallowRenderer from 'react-shallow-renderer';
const renderer = new ShallowRenderer();
renderer.render(<MyComponent prop={1} />); Defensive patterns
Strategy: fallback
Validate before calling
// Feature-detect before importing the removed submodule
let ShallowRenderer;
try {
({default: ShallowRenderer} = await import('react-test-renderer/shallow'));
} catch {
({default: ShallowRenderer} = await import('react-shallow-renderer')); // community replacement
} Try / catch
// Only if you must support both React versions
let renderer;
try {
const Mod = await import('react-test-renderer/shallow');
renderer = new Mod.default();
} catch (e) {
if (/react-test-renderer\/shallow has been removed/.test(e.message)) {
const {default: Shallow} = await import('react-shallow-renderer');
renderer = new Shallow();
} else {
throw e;
}
} Prevention
- Migrate shallow tests to react-shallow-renderer or @testing-library/react before upgrading to React 19
- Run a codemod/grep for 'react-test-renderer/shallow' as part of the React major upgrade checklist
When it happens
Trigger: Executing import ShallowRenderer from 'react-test-renderer/shallow' (or require('react-test-renderer/shallow')) under React 19+, or calling the exported function.
Common situations: Upgrading a legacy Enzyme-style test suite or snapshot tests that relied on shallow rendering; transitive dependencies (old enzyme adapters) importing the submodule after a React major bump.
Related errors
- 509
- Did not expect a host hoistable to be the root
- No instances found ${message}
- Expected 1 but found ${all.length} instances ${message}
- Can't access .root on unmounted test renderer
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/27f9e76426c3f42e.
Report an issue: GitHub.