Runtime environment variables not respected in API routes after upgrading to Next.js 16 #86209
Unanswered
acasamassimacrif
asked this question in
Help
Replies: 1 comment 5 replies
-
|
import { NextResponse, connection } from "next/server";
export async function GET() {
await connection();
// NOPE - These are NEXT_PUBLIC_ prefixed, so they are inlined.
return NextResponse.json({
NEXT_PUBLIC_BASE_URL: process.env.NEXT_PUBLIC_BASE_URL ?? null,
NEXT_PUBLIC_APP_VERSION: process.env.NEXT_PUBLIC_APP_VERSION ?? null,
});
}
Edit: I had missed the NEXT_PUBLIC_ prefix... that inlines them at build time with the DefinePlugin |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
After upgrading from Next.js 15 to Next.js 16, runtime environment variables injected into the container (e.g., via Docker or Kubernetes pod) are no longer correctly read by API routes.
Previously, in Next.js 15, API routes using export const dynamic = "force-dynamic" returned the runtime values of environment variables. Now, in Next.js 16, the same API routes always return the .env values bundled at build time, ignoring runtime overrides.
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions