vercel/next.js · error · Error

The key " " under "env" in is not allowed…

Error message

The key "${key}" under "env" in ${config.configFileName || 'config'} is not allowed. https://nextjs.org/docs/messages/env-key-not-allowed

What it means

Env-name validation in errorIfEnvConflicted: a key under next.config's env map matched the reserved patterns NODE_*, __*, or was exactly NEXT_RUNTIME. Those names are controlled by Next.js/Node itself, so injecting them via config would silently override runtime behavior and is rejected.

Solutions

  1. Remove the disallowed key from the env config; keys starting with NODE_ or reserved names cannot be used.
Defensive patterns

Strategy: validation

When it happens

Trigger: A disallowed key is defined under env in next.config.

Common situations: Defining a reserved or NODE_ENV-like key in the env config block.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/af632575993fcef0. Report an issue: GitHub.

Appendix: source

Thrown at packages/next/src/lib/static-env.ts:14

import type {
  NextConfigComplete,
  NextConfigRuntime,
} from '../server/config-shared'

function errorIfEnvConflicted(
  config: NextConfigComplete | NextConfigRuntime,
  key: string
) {
  const isPrivateKey = /^(?:NODE_.+)|^(?:__.+)$/i.test(key)
  const hasNextRuntimeKey = key === 'NEXT_RUNTIME'

  if (isPrivateKey || hasNextRuntimeKey) {
    throw new Error(
      `The key "${key}" under "env" in ${config.configFileName || 'config'} is not allowed. https://nextjs.org/docs/messages/env-key-not-allowed`
    )
  }
}

/**
 * Collects all environment variables that are using the `NEXT_PUBLIC_` prefix.
 */
export function getNextPublicEnvironmentVariables() {
  const defineEnv: [string, string | undefined][] = []
  for (const key in process.env) {
    if (key.startsWith('NEXT_PUBLIC_')) {
      const value = process.env[key]
      if (value != null) {
        defineEnv.push([`process.env.${key}`, value])
      }
    }
  }

View on GitHub (pinned to 0eb3775416)