Full answer
React ships one package with two flavours of code, chosen at build time by the value of process.env.NODE_ENV. Bundlers replace that expression with a literal ("development" or "production") and then remove the branches that cannot run (dead code elimination).
Development build. It contains validation and warnings: unique key warnings, invalid hook calls, wrong prop usage, hydration mismatch diffs, DevTools hooks, extra runtime checks, and Strict Mode's double invocation. These make debugging easier but add size and slow down rendering, sometimes by a large factor. Profiling in development gives misleading numbers.
Production build. The checks and error message strings are removed (React keeps short error codes that link to a decoder page), identifiers are minified, and code is smaller and faster. DevTools profiling is limited unless you use a special profiling build.
Consequences:
- Always test performance, bundle size and Lighthouse scores against the production build (
vite buildthenvite preview, ornext buildthennext start). - Never deploy the dev server. It serves unbundled modules and is not hardened.
- Code that behaves differently in production is usually relying on dev-only behaviour (double rendering, warnings, error overlays).
- Your own code can branch on the mode, for example to enable debug tools in development only. The bundler removes the dead branch.
- If the replacement is missing and
processis undefined in the browser, bundles fail at runtime, so make sure the build defines it (Vite does this for you withimport.meta.env.MODE).
Other build outputs worth knowing: source maps (upload to error monitoring, avoid exposing them if source is private), content hashes in file names for caching, and separate chunks for code splitting.
The example uses esbuild to bundle React for both modes and compares them.
import { build } from 'esbuild';
import { mkdtemp, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
const dir = await mkdtemp(path.join(tmpdir(), 'modes-'));
await writeFile(
path.join(dir, 'entry.jsx'),
"import { createRoot } from 'react-dom/client';\ncreateRoot(document.body).render(<h1>Hello</h1>);\n"
);
async function size(mode) {
const result = await build({
entryPoints: [path.join(dir, 'entry.jsx')],
bundle: true,
minify: true,
jsx: 'automatic',
write: false,
nodePaths: [path.resolve('node_modules')],
define: { 'process.env.NODE_ENV': JSON.stringify(mode) },
outfile: path.join(dir, mode + '.js'),
});
return result.outputFiles[0].contents.length;
}
const development = await size('development');
const production = await size('production');
console.log('development bundle is larger than production: ' + (development > production));
console.log('production is smaller by more than 25 percent: ' + (production < development * 0.75));This ran esbuild on the box for both modes with a tiny entry file that imports react-dom. The comparison is about relative size and does not give exact numbers, which depend on versions. Output of the run: development bundle is larger than production: true production is smaller by more than 25 percent: true
Key points
- Bundlers choose the React build from NODE_ENV and remove dead branches.
- The development build adds warnings and checks and is larger and slower.
- Production strips checks, minifies and uses error codes instead of messages.
- Measure and ship only the production build. Never deploy the dev server.
- Use source maps and hashed file names for debugging and caching.
Common mistakes
- Measuring performance in development mode.
- Deploying the development server.
- Forgetting to define process.env.NODE_ENV for a custom bundler setup.
- Publishing source maps of private source code publicly.
- Relying on development-only behaviour such as double rendering.
Follow-ups
- What is the profiling build of React and when would you use it?
- How do bundlers remove dead code?
- How do you read production error codes from React?
Tips
- Mention NODE_ENV and dead code elimination.
- Say you profile only production builds.
- Name two things the dev build adds.