{"record":{"id":"b02958720aa65383","repo":"toeverything/AFFiNE","slug":"invalid-node-env-environment-this-node-env-i","errorCode":null,"errorMessage":"Invalid NODE_ENV environment. `${this.NODE_ENV}` is not a valid NODE_ENV value.","messagePattern":"Invalid NODE_ENV environment\\. `(.+?)` is not a valid NODE_ENV value\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/backend/server/src/env.ts","lineNumber":186,"sourceCode":"  get testing() {\n    return this.NODE_ENV === NodeEnv.Test;\n  }\n\n  get dev() {\n    return this.NODE_ENV === NodeEnv.Development;\n  }\n\n  get prod() {\n    return this.NODE_ENV === NodeEnv.Production;\n  }\n\n  get gcp() {\n    return this.platform === Platform.GCP;\n  }\n\n  constructor() {\n    if (!Object.values(NodeEnv).includes(this.NODE_ENV)) {\n      throw new Error(\n        `Invalid NODE_ENV environment. \\`${this.NODE_ENV}\\` is not a valid NODE_ENV value.`\n      );\n    }\n  }\n}\n\nexport const createGlobalEnv = () => {\n  if (!globalThis.env) {\n    globalThis.env = new Env();\n  }\n};\n","sourceCodeStart":168,"sourceCodeEnd":198,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/591f874dad30887a80143a061a44bd3ca7ee3299/packages/backend/server/src/env.ts#L168-L198","documentation":"Thrown by the Env class constructor when NODE_ENV is set to anything other than development, test, or production (the NodeEnv enum). The value defaults to production when unset, so this only fires when a bad value was explicitly provided; the process fails at env creation time.","triggerScenarios":"Starting the server with NODE_ENV=staging, NODE_ENV=dev, NODE_ENV=prod, or any non-enum value — note that abbreviations like 'dev'/'prod' are NOT accepted.","commonSituations":"Porting NODE_ENV from another framework that permits arbitrary values; writing NODE_ENV=dev out of habit; CI pipelines injecting a custom stage name.","solutions":["Use one of the full words: NODE_ENV=development, NODE_ENV=test, or NODE_ENV=production.","Remove NODE_ENV entirely if production is intended (it is the default).","Audit docker-compose/CI matrix so no stage-specific custom values leak into NODE_ENV (use AFFINE_ENV=beta for stage separation instead)."],"exampleFix":"# before\nNODE_ENV=dev\n# after\nNODE_ENV=development","handlingStrategy":"validation","validationCode":"// Preflight check in a bootstrap script\nconst NODE_ENVS = ['development', 'test', 'production'];\nif (process.env.NODE_ENV && !NODE_ENVS.includes(process.env.NODE_ENV)) {\n  throw new Error(`NODE_ENV must be one of ${NODE_ENVS.join('|')} (or unset)`);\n}","typeGuard":"const isValidNodeEnv = (value: string): boolean =>\n  ['development', 'test', 'production'].includes(value);","tryCatchPattern":null,"preventionTips":["Never use NODE_ENV abbreviations (dev/prod) or stage names; use full enum words or leave it unset.","Use AFFINE_ENV for namespace/stage separation and reserve NODE_ENV for the three standard values."],"tags":["environment","node-env","startup","configuration"],"backgroundTag":"invalid-env-var-value","analyzedSha":"591f874dad30887a80143a061a44bd3ca7ee3299","analyzedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}