{"record":{"id":"d8484e44d554e262","repo":"react/create-react-app","slug":"using-babel-preset-react-app-requires-that-you-s-d8484e","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/dependencies.js","lineNumber":54,"sourceCode":"  var isEnvProduction = env === 'production';\n  var isEnvTest = env === 'test';\n\n  var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, false);\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    // Babel assumes ES Modules, which isn't safe until CommonJS\n    // dies. This changes the behavior to assume CommonJS unless\n    // an `import` or `export` is present in the file.\n    // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940\n    sourceType: 'unambiguous',\n    presets: [\n      isEnvTest && [\n        // ES features necessary for user's Node version\n        require('@babel/preset-env').default,","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/react/create-react-app/blob/6254386531d263688ccfa542d0e628fbc0de0b28/packages/babel-preset-react-app/dependencies.js#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// .babelrc.js\nmodule.exports = { presets: ['babel-preset-react-app/dependencies'] };\n// run: babel src --out-dir lib   (no NODE_ENV)\n// after\n// run with: cross-env NODE_ENV=production babel src --out-dir lib","handlingStrategy":"validation","validationCode":"const VALID_ENVS = ['development', 'test', 'production'];\nfunction assertDepsEnv() {\n  const env = process.env.BABEL_ENV || process.env.NODE_ENV;\n  if (!VALID_ENVS.includes(env)) {\n    throw new Error(`Set NODE_ENV/BABEL_ENV for the dependencies pass (got ${String(env)})`);\n  }\n}\nassertDepsEnv();","typeGuard":"const isKnownEnv = (e) =>\n  ['development', 'test', 'production'].includes(e);","tryCatchPattern":"try {\n  babel.transform(code, { presets: ['babel-preset-react-app/dependencies'] });\n} catch (e) {\n  if (/NODE_ENV|BABEL_ENV/.test(e.message)) {\n    console.error('Dependencies pass needs NODE_ENV set to development/test/production');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["environment","babel","node-env","dependencies","preset"],"backgroundTag":null,"analyzedSha":"6254386531d263688ccfa542d0e628fbc0de0b28","analyzedAt":"2026-08-12T22:55:01.751Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}