{"record":{"id":"af632575993fcef0","repo":"vercel/next.js","slug":"the-key-key-under-env-in-config-configfil","errorCode":null,"errorMessage":"The key \"${key}\" under \"env\" in ${config.configFileName || 'config'} is not allowed. https://nextjs.org/docs/messages/env-key-not-allowed","messagePattern":"The key \"(.+?)\" under \"env\" in (.+?) is not allowed\\. https://nextjs\\.org/docs/messages/env-key-not-allowed","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/lib/static-env.ts","lineNumber":14,"sourceCode":"import type {\n  NextConfigComplete,\n  NextConfigRuntime,\n} from '../server/config-shared'\n\nfunction errorIfEnvConflicted(\n  config: NextConfigComplete | NextConfigRuntime,\n  key: string\n) {\n  const isPrivateKey = /^(?:NODE_.+)|^(?:__.+)$/i.test(key)\n  const hasNextRuntimeKey = key === 'NEXT_RUNTIME'\n\n  if (isPrivateKey || hasNextRuntimeKey) {\n    throw new Error(\n      `The key \"${key}\" under \"env\" in ${config.configFileName || 'config'} is not allowed. https://nextjs.org/docs/messages/env-key-not-allowed`\n    )\n  }\n}\n\n/**\n * Collects all environment variables that are using the `NEXT_PUBLIC_` prefix.\n */\nexport function getNextPublicEnvironmentVariables() {\n  const defineEnv: [string, string | undefined][] = []\n  for (const key in process.env) {\n    if (key.startsWith('NEXT_PUBLIC_')) {\n      const value = process.env[key]\n      if (value != null) {\n        defineEnv.push([`process.env.${key}`, value])\n      }\n    }\n  }","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/lib/static-env.ts#L1-L32","documentation":"Thrown by errorIfEnvConflicted() when a key in the next.config.js `env` map matches a reserved pattern. Next.js forbids NODE_* (e.g. NODE_ENV, NODE_OPTIONS), any __-prefixed key, and the literal NEXT_RUNTIME, because assigning those via config would shadow or break Node/Next internal behavior. The check runs while collecting static env vars for the build.","triggerScenarios":"Setting env: { NODE_ENV: 'production' }, env: { __NEXT_DATA__: '...' }, or env: { NEXT_RUNTIME: 'nodejs' } in next.config.js or next.config.ts. Any key matching /^(?:NODE_.+)|^(?:__.+)$/i or exactly 'NEXT_RUNTIME' triggers it.","commonSituations":"Copying environment variables wholesale into the `env` config block (a common mistake when migrating from .env files), or attempting to override Node runtime flags via config. Often seen when developers try to force NODE_ENV in config rather than via the environment.","solutions":["Remove the offending key (NODE_*, __*, or NEXT_RUNTIME) from the `env` map in your next.config file.","Set NODE_ENV via the actual process environment (e.g. in your hosting platform or package.json script) rather than the `env` config.","If you need a custom var, rename it to a non-reserved prefix (e.g. APP_NODE_ID instead of NODE_ID)."],"exampleFix":"// before (next.config.js)\nmodule.exports = { env: { NODE_ENV: 'production', NEXT_RUNTIME: 'nodejs' } }\n// after\nmodule.exports = { env: { APP_RELEASE: 'v1' } } // NODE_ENV set by the platform, not config","handlingStrategy":"validation","validationCode":"const RESERVED_ENV_KEY = /^(?:NODE_.+)|^(?:__.+)$/i\nfunction validateEnvKeys(env: Record<string, unknown>) {\n  for (const key of Object.keys(env)) {\n    if (RESERVED_ENV_KEY.test(key) || key === 'NEXT_RUNTIME') {\n      throw new Error(`Reserved env key '${key}' cannot be set in next.config env`)\n    }\n  }\n}","typeGuard":"function isAllowedEnvKey(key: string): boolean {\n  return !(/^(?:NODE_.+)|^(?:__.+)$/i.test(key) || key === 'NEXT_RUNTIME')\n}","tryCatchPattern":null,"preventionTips":["Never put NODE_*, __*, or NEXT_RUNTIME in the next.config `env` map.","Set NODE_ENV via the process environment (platform/script), not config.","Review the `env` block after copying variables from a .env file."],"tags":["config","environment-variables","build"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}