facebook/react · warning · Error
React is running in production mode, but dead code eliminati
Error message
React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://react.dev/link/perf-use-production-build
What it means
When DevTools attaches to a production React renderer, it stringifies a function that contains a DEV-only marker ('^_^'). Seeing that marker in a production build proves the bundler did not inline/eliminate process.env.NODE_ENV branches, so React is running both dev and prod code paths — larger and slower. The error is thrown asynchronously (setTimeout) so error-reporting systems can catch it without breaking the host page.
Source
Thrown at packages/react-devtools-shared/src/hook.js:196
function checkDCE(fn: Function) {
// This runs for production versions of React.
// Needs to be super safe.
try {
// $FlowFixMe[method-unbinding]
const toString = Function.prototype.toString;
const code = toString.call(fn);
// This is a string embedded in the passed function under DEV-only
// condition. However the function executes only in PROD. Therefore,
// if we see it, dead code elimination did not work.
if (code.indexOf('^_^') > -1) {
// Remember to report during next injection.
hasDetectedBadDCE = true;
// Bonus: throw an exception hoping that it gets picked up by a reporting system.
// Not synchronously so that it doesn't break the calling code.
setTimeout(function () {
throw new Error(
'React is running in production mode, but dead code ' +
'elimination has not been applied. Read how to correctly ' +
'configure React for production: ' +
'https://react.dev/link/perf-use-production-build',
);
});
}
} catch (err) {}
}
// TODO: isProfiling should be stateful, and we should update it once profiling is finished
const isProfiling = shouldStartProfilingNow;
let uidCounter = 0;
function inject(renderer: ReactRenderer): number {
const id = ++uidCounter;
renderers.set(id, renderer);
const reactBuildType: ReactBuildType = hasDetectedBadDCEView on GitHub (pinned to eafeac097b)
Solutions
- Inline NODE_ENV in your bundler: webpack DefinePlugin({'process.env.NODE_ENV': '"production"'}), Vite/esbuild define, or @rollup/plugin-replace.
- Use the published prebuilt production React artifacts rather than bundling React from source.
- Add a CI check: the built bundle must not contain 'process.env.NODE_ENV' or the '^_^' marker.
Example fix
// before — webpack.config.js
module.exports = { mode: 'production' };
// after
const webpack = require('webpack');
module.exports = {
mode: 'production',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
}; Defensive patterns
Strategy: validation
Validate before calling
// CI guard: production bundles must not contain un-inlined env or the DEV marker
const fs = require('fs');
const bundle = fs.readFileSync('dist/bundle.js', 'utf8');
if (bundle.includes('process.env.NODE_ENV') || bundle.includes('^_^')) {
throw new Error('Dead code elimination failed: inline process.env.NODE_ENV in the bundler config');
} Try / catch
window.addEventListener('error', event => {
if (/dead code elimination/.test(String(event.error && event.error.message))) {
reportBuildIssue(event.error); // build config problem, not a runtime bug
}
}); Prevention
- Always define process.env.NODE_ENV in production bundler config (DefinePlugin/define/replace).
- Prefer published production React builds over bundling React from source.
- Grep the shipped bundle for 'process.env.NODE_ENV' in CI to catch regressions.
- Recognize this error in reporting tools as a build misconfiguration, not an app crash.
When it happens
Trigger: checkDCE(fn) runs during renderer injection with a production-flagged React whose code still contains the DEV marker — i.e. React was bundled from source without DefinePlugin/replace-style env inlining, or a dev build is masquerading as production.
Common situations: Bundling React from source with webpack missing mode/DefinePlugin; esbuild/Vite/Rollup builds without the process.env.NODE_ENV define; consuming un-envified React via a transpiling CDN or bundling node_modules; CI only appearing in error trackers as an async uncaught error.
Related errors
- This module must be shimmed by a specific renderer.
- An unsupported type was passed to use(): ${String(usable)}
- Unknown Fiber. Needs to be a function component to inspect h
- Section offsets must be ordered and non-overlapping.
- react-dom/client is not supported in React Server Components
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/4bde6fc354b7cb75.
Report an issue: GitHub.