react/create-react-app · critical · Error
Using `babel-preset-react-app` requires that you specify `NO
Error message
Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: ${JSON.stringify(env)}. What it means
create.js derives isEnvDevelopment/isEnvProduction/isEnvTest by comparing the active Babel environment to the literal strings. If none match, the preset cannot decide which transforms to apply and aborts. The environment comes from BABEL_ENV, falling back to NODE_ENV, surfaced here as the `env` argument.
Source
Thrown at packages/babel-preset-react-app/create.js:58
opts.typescript,
true
);
var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, true);
var useAbsoluteRuntime = validateBoolOption(
'absoluteRuntime',
opts.absoluteRuntime,
true
);
var absoluteRuntimePath = undefined;
if (useAbsoluteRuntime) {
absoluteRuntimePath = path.dirname(
require.resolve('@babel/runtime/package.json')
);
}
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
throw new Error(
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(env) +
'.'
);
}
return {
presets: [
isEnvTest && [
// ES features necessary for user's Node version
require('@babel/preset-env').default,
{
targets: {
node: 'current',
},
},View on GitHub (pinned to 6254386531)
Solutions
- Export NODE_ENV to one of development/test/production before invoking the toolchain: `NODE_ENV=development npm run <script>`.
- Set BABEL_ENV explicitly if NODE_ENV must stay different: `BABEL_ENV=test`.
- Add `cross-env NODE_ENV=development` (or test/production) to the relevant script in package.json for OS-portable behavior.
- If running under Jest, ensure the test script or jest config sets NODE_ENV=test (react-scripts does this in scripts/test.js).
Example fix
// before
// package.json
"scripts": { "build:lib": "babel src --out-dir lib" }
// after
"scripts": { "build:lib": "cross-env NODE_ENV=production babel src --out-dir lib" } Defensive patterns
Strategy: validation
Validate before calling
// Validate the environment before Babel ever loads the preset.
const VALID_ENVS = ['development', 'test', 'production'];
function ensureBabelEnv() {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (!VALID_ENVS.includes(env)) {
throw new Error(
`Set NODE_ENV/BABEL_ENV to one of ${VALID_ENVS.join(', ')} (got: ${String(env)})`
);
}
return env;
}
ensureBabelEnv(); Type guard
const isKnownEnv = (e) => e === 'development' || e === 'test' || e === 'production';
Try / catch
try {
babel.transformFileSync(file, { presets: ['react-app'] });
} catch (e) {
if (/NODE_ENV|BABEL_ENV/.test(e.message)) {
console.error('Missing env. Run with NODE_ENV=development|test|production');
process.exit(1);
}
throw e;
} Prevention
- Always run babel through scripts that set NODE_ENV (react-scripts does this).
- Use cross-env in package.json scripts for OS-portable env vars.
- In CI, export NODE_ENV at the job level so all steps inherit it.
- Add a startup assertion for NODE_ENV in custom entry points.
When it happens
Trigger: Loading babel-preset-react-app when BABEL_ENV/NODE_ENV is unset, empty string, or set to any value other than 'development', 'test', or 'production' (e.g. 'staging', 'ci'). The branch `!isEnvDevelopment && !isEnvProduction && !isEnvTest` is true and throws.
Common situations: Running Jest/Babel directly in a fresh shell without NODE_ENV. CI images that don't export NODE_ENV. Setting NODE_ENV to a custom stage name. Using the preset outside react-scripts (e.g. in a custom build) without replicating react-scripts' env setup.
Related errors
- Using `babel-preset-react-app` requires that you specify `NO
- Preset react-app: '${name}' option must be a boolean.
- Preset react-app: '${name}' option must be a boolean.
- The NODE_ENV environment variable is required but was not sp
AI-assisted analysis of react/create-react-app@6254386531 (2026-08-12).
Data as JSON: /api/errors/d410c066e7d796c2.
Report an issue: GitHub.