{"record":{"id":"d410c066e7d796c2","repo":"react/create-react-app","slug":"using-babel-preset-react-app-requires-that-you-s","errorCode":null,"errorMessage":"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)}.","messagePattern":"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: (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/babel-preset-react-app/create.js","lineNumber":58,"sourceCode":"    opts.typescript,\n    true\n  );\n  var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, true);\n  var useAbsoluteRuntime = validateBoolOption(\n    'absoluteRuntime',\n    opts.absoluteRuntime,\n    true\n  );\n\n  var absoluteRuntimePath = undefined;\n  if (useAbsoluteRuntime) {\n    absoluteRuntimePath = path.dirname(\n      require.resolve('@babel/runtime/package.json')\n    );\n  }\n\n  if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {\n    throw new Error(\n      'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +\n        '`BABEL_ENV` environment variables. Valid values are \"development\", ' +\n        '\"test\", and \"production\". Instead, received: ' +\n        JSON.stringify(env) +\n        '.'\n    );\n  }\n\n  return {\n    presets: [\n      isEnvTest && [\n        // ES features necessary for user's Node version\n        require('@babel/preset-env').default,\n        {\n          targets: {\n            node: 'current',\n          },\n        },","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/react/create-react-app/blob/6254386531d263688ccfa542d0e628fbc0de0b28/packages/babel-preset-react-app/create.js#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\n// package.json\n\"scripts\": { \"build:lib\": \"babel src --out-dir lib\" }\n// after\n\"scripts\": { \"build:lib\": \"cross-env NODE_ENV=production babel src --out-dir lib\" }","handlingStrategy":"validation","validationCode":"// Validate the environment before Babel ever loads the preset.\nconst VALID_ENVS = ['development', 'test', 'production'];\nfunction ensureBabelEnv() {\n  const env = process.env.BABEL_ENV || process.env.NODE_ENV;\n  if (!VALID_ENVS.includes(env)) {\n    throw new Error(\n      `Set NODE_ENV/BABEL_ENV to one of ${VALID_ENVS.join(', ')} (got: ${String(env)})`\n    );\n  }\n  return env;\n}\nensureBabelEnv();","typeGuard":"const isKnownEnv = (e) =>\n  e === 'development' || e === 'test' || e === 'production';","tryCatchPattern":"try {\n  babel.transformFileSync(file, { presets: ['react-app'] });\n} catch (e) {\n  if (/NODE_ENV|BABEL_ENV/.test(e.message)) {\n    console.error('Missing env. Run with NODE_ENV=development|test|production');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["environment","babel","node-env","preset"],"backgroundTag":null,"analyzedSha":"6254386531d263688ccfa542d0e628fbc0de0b28","analyzedAt":"2026-08-12T22:55:01.751Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}