{"record":{"id":"4bde6fc354b7cb75","repo":"facebook/react","slug":"react-is-running-in-production-mode-but-dead-code","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/react-devtools-shared/src/hook.js","lineNumber":196,"sourceCode":"  function checkDCE(fn: Function) {\n    // This runs for production versions of React.\n    // Needs to be super safe.\n    try {\n      // $FlowFixMe[method-unbinding]\n      const toString = Function.prototype.toString;\n      const code = toString.call(fn);\n\n      // This is a string embedded in the passed function under DEV-only\n      // condition. However the function executes only in PROD. Therefore,\n      // if we see it, dead code elimination did not work.\n      if (code.indexOf('^_^') > -1) {\n        // Remember to report during next injection.\n        hasDetectedBadDCE = true;\n\n        // Bonus: throw an exception hoping that it gets picked up by a reporting system.\n        // Not synchronously so that it doesn't break the calling code.\n        setTimeout(function () {\n          throw new Error(\n            'React is running in production mode, but dead code ' +\n              'elimination has not been applied. Read how to correctly ' +\n              'configure React for production: ' +\n              'https://react.dev/link/perf-use-production-build',\n          );\n        });\n      }\n    } catch (err) {}\n  }\n\n  // TODO: isProfiling should be stateful, and we should update it once profiling is finished\n  const isProfiling = shouldStartProfilingNow;\n  let uidCounter = 0;\n  function inject(renderer: ReactRenderer): number {\n    const id = ++uidCounter;\n    renderers.set(id, renderer);\n\n    const reactBuildType: ReactBuildType = hasDetectedBadDCE","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-devtools-shared/src/hook.js#L178-L214","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — webpack.config.js\nmodule.exports = { mode: 'production' };\n\n// after\nconst webpack = require('webpack');\nmodule.exports = {\n  mode: 'production',\n  plugins: [\n    new webpack.DefinePlugin({\n      'process.env.NODE_ENV': JSON.stringify('production'),\n    }),\n  ],\n};","handlingStrategy":"validation","validationCode":"// CI guard: production bundles must not contain un-inlined env or the DEV marker\nconst fs = require('fs');\nconst bundle = fs.readFileSync('dist/bundle.js', 'utf8');\nif (bundle.includes('process.env.NODE_ENV') || bundle.includes('^_^')) {\n  throw new Error('Dead code elimination failed: inline process.env.NODE_ENV in the bundler config');\n}","typeGuard":null,"tryCatchPattern":"window.addEventListener('error', event => {\n  if (/dead code elimination/.test(String(event.error && event.error.message))) {\n  reportBuildIssue(event.error); // build config problem, not a runtime bug\n  }\n});","preventionTips":["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."],"tags":["production","dead-code-elimination","bundler","performance","react"],"backgroundTag":"dead-code-elimination-missing","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}