{"record":{"id":"79dd09fc284ee0c4","repo":"appsmithorg/appsmith","slug":"the-node-env-environment-variable-is-required-but","errorCode":null,"errorMessage":"The NODE_ENV environment variable is required but was not specified.","messagePattern":"The NODE_ENV environment variable is required but was not specified\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"app/client/config/env.js","lineNumber":12,"sourceCode":"\"use strict\";\n\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst paths = require(\"./paths\");\n\n// Make sure that including paths.js after env.js will read .env variables.\ndelete require.cache[require.resolve(\"./paths\")];\n\nconst NODE_ENV = process.env.NODE_ENV;\nif (!NODE_ENV) {\n  throw new Error(\n    \"The NODE_ENV environment variable is required but was not specified.\",\n  );\n}\n\n// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use\nconst dotenvFiles = [\n  `${paths.dotenv}.${NODE_ENV}.local`,\n  // Don't include `.env.local` for `test` environment\n  // since normally you expect tests to produce the same\n  // results for everyone\n  NODE_ENV !== \"test\" && `${paths.dotenv}.local`,\n  `${paths.dotenv}.${NODE_ENV}`,\n  paths.dotenv,\n].filter(Boolean);\n\n// Load environment variables from .env* files. Suppress warnings using silent\n// if this file is missing. dotenv will never modify any environment variables\n// that have already been set.  Variable expansion is supported in .env files.","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/appsmithorg/appsmith/blob/8cd9021c24cdbea1c3c12c966073708e83db60c2/app/client/config/env.js#L1-L30","documentation":"Thrown by Appsmith's client build config (a Create React App fork) in config/env.js. The build pipeline reads process.env.NODE_ENV to decide which .env file set to load and which webpack mode to run. Because every downstream decision (dev vs prod optimizations, .env.local inclusion, minification) depends on it, env.js refuses to boot without an explicit value. It is a hard precondition gate before any webpack config is assembled.","triggerScenarios":"Running a react-scripts-based script (start/build/test) in a context where NODE_ENV is unset: a raw 'node config/env.js', a CI runner that does not export NODE_ENV, a Docker image started with an empty env, or a custom npm script that calls the webpack config directly instead of going through react-scripts which normally injects NODE_ENV.","commonSituations":"CI pipelines that invoke the build without 'cross-env NODE_ENV=production'; Docker containers that drop the env var; IDE run configurations that spawn node directly; upgrading react-scripts where the injected NODE_ENV contract changed; shell sessions where NODE_ENV was never exported.","solutions":["Set NODE_ENV explicitly before the build command, e.g. run scripts via react-scripts (which sets it) or prefix with 'NODE_ENV=production' / 'cross-env NODE_ENV=development'.","If running inside Docker, add ENV NODE_ENV=production to the Dockerfile or pass -e NODE_ENV=production to docker run.","In CI, export NODE_ENV in the job step before the npm script executes.","Avoid requiring config/env.js from custom Node scripts; use react-scripts entry points which set NODE_ENV for you."],"exampleFix":"// before\n$ node config/env.js\n// Error: The NODE_ENV environment variable is required...\n\n// after\n$ NODE_ENV=production node config/env.js\n// or, in package.json scripts, use the CRA wrapper which injects it:\n//   \"build\": \"react-scripts build\"","handlingStrategy":"validation","validationCode":"if (!process.env.NODE_ENV) {\n  throw new Error('Set NODE_ENV before running the build (development|production|test).');\n}","typeGuard":"const isNodeEnv = (v: string | undefined): v is 'development'|'production'|'test' =>\n  v === 'development' || v === 'production' || v === 'test';","tryCatchPattern":null,"preventionTips":["Always invoke builds through react-scripts / the project npm scripts, which inject NODE_ENV.","Set NODE_ENV in CI job env and Dockerfile ENV so it is never absent.","Add a prebuild check that fails fast with a clearer message if NODE_ENV is unset."],"tags":["configuration","environment-variables","build","react-scripts"],"backgroundTag":null,"analyzedSha":"8cd9021c24cdbea1c3c12c966073708e83db60c2","analyzedAt":"2026-08-12T22:14:19.293Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}