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
dependencies.js performs the same NODE_ENV/BABEL_ENV gate as create.js. Before returning its plugin list it asserts the active environment is one of development/test/production. The dependencies entry needs the environment to choose CommonJS vs ESM assumptions and module transformations, so an unknown env is fatal.
Source
Thrown at packages/babel-preset-react-app/dependencies.js:54
var isEnvProduction = env === 'production';
var isEnvTest = env === 'test';
var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, false);
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 {
// Babel assumes ES Modules, which isn't safe until CommonJS
// dies. This changes the behavior to assume CommonJS unless
// an `import` or `export` is present in the file.
// https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
sourceType: 'unambiguous',
presets: [
isEnvTest && [
// ES features necessary for user's Node version
require('@babel/preset-env').default,View on GitHub (pinned to 6254386531)
Solutions
- Set NODE_ENV (or BABEL_ENV) to development/test/production in the shell or script that runs the dependencies compile.
- Use cross-env in package.json to set NODE_ENV portably: `cross-env NODE_ENV=production babel ...`.
- If invoking programmatically, pass the env explicitly to the preset's third argument as Babel resolves it.
- Ensure your CI runner exports NODE_ENV for the job.
Example fix
// before
// .babelrc.js
module.exports = { presets: ['babel-preset-react-app/dependencies'] };
// run: babel src --out-dir lib (no NODE_ENV)
// after
// run with: cross-env NODE_ENV=production babel src --out-dir lib Defensive patterns
Strategy: validation
Validate before calling
const VALID_ENVS = ['development', 'test', 'production'];
function assertDepsEnv() {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (!VALID_ENVS.includes(env)) {
throw new Error(`Set NODE_ENV/BABEL_ENV for the dependencies pass (got ${String(env)})`);
}
}
assertDepsEnv(); Type guard
const isKnownEnv = (e) => ['development', 'test', 'production'].includes(e);
Try / catch
try {
babel.transform(code, { presets: ['babel-preset-react-app/dependencies'] });
} catch (e) {
if (/NODE_ENV|BABEL_ENV/.test(e.message)) {
console.error('Dependencies pass needs NODE_ENV set to development/test/production');
process.exit(1);
}
throw e;
} Prevention
- Run the dependencies compile through an npm script that sets NODE_ENV.
- Use cross-env to set NODE_ENV portably across OSes.
- Add a prebuild step that asserts the environment.
- Document in your build README that the dependencies pass requires NODE_ENV.
When it happens
Trigger: Loading babel-preset-react-app/dependencies when neither BABEL_ENV nor NODE_ENV is one of the three valid values (unset, empty, or a custom stage). The `!isEnvDevelopment && !isEnvProduction && !isEnvTest` guard triggers.
Common situations: A dependencies-only Babel pass invoked from a script that doesn't set NODE_ENV. Monorepo tooling that runs Babel over node_modules/dependencies in a CI shell missing env vars. Reusing the entry outside react-scripts without replicating its 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/d8484e44d554e262.
Report an issue: GitHub.