Next.js 15: Environment variables missing in API Routes

I’m experiencing a critical issue where ALL non-NEXT_PUBLIC_ environment variables are unavailable at runtime in Next.js API Routes (Route Handlers), even though they’re correctly configured in the Vercel dashboard. This is blocking production functionality that requires server-side environment variables like SUPABASE_SERVICE_ROLE_KEY.

Current versus Expected behavior:

Current Behavior:

  • All non-NEXT_PUBLIC_ environment variables are completely missing from process.env at runtime in API Routes
  • SUPABASE_SERVICE_ROLE_KEY is not available (returns undefined)
  • TEST_SERVICE_KEY (test variable) is also not available
  • Only NEXT_PUBLIC_* variables work correctly

Expected Behavior:

  • All environment variables set in Vercel dashboard should be available in process.env at runtime in API Routes
  • SUPABASE_SERVICE_ROLE_KEY should be accessible via process.env.SUPABASE_SERVICE_ROLE_KEY
  • Both NEXT_PUBLIC_* and non-NEXT_PUBLIC_ variables should work

Test Endpoint Results:
I created a test endpoint (/api/test-env) that checks available environment variables:
{
“hasSupabaseServiceRoleKey”: false,
“hasTestServiceKey”: false,
“availableSupabaseVars”: [“NEXT_PUBLIC_SUPABASE_ANON_KEY”, “NEXT_PUBLIC_SUPABASE_URL”],
“allEnvVarNames”: [/* SUPABASE_SERVICE_ROLE_KEY and TEST_SERVICE_KEY are completely missing */]
}Code, configuration, and steps that reproduce this issue:

**Test Endpoint Code:**ipt
// app/api/test-env/route.ts
import { NextRequest, NextResponse } from “next/server”;

export async function GET(request: NextRequest) {
const envCheck = {
hasSupabaseServiceRoleKey: !!process.env.SUPABASE_SERVICE_ROLE_KEY,
hasTestServiceKey: !!process.env.TEST_SERVICE_KEY,
availableSupabaseVars: Object.keys(process.env)
.filter((key) => key.includes(“SUPABASE”) || key.includes(“TEST”))
.sort(),
};
return NextResponse.json(envCheck, { status: 200 });
}API Route Example (failing):
// app/api/search-players/route.ts
export async function GET(request: NextRequest) {
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY; // Returns undefined
// … rest of code fails because key is missing
}next.config.ts:
import type { NextConfig } from “next”;

const nextConfig: NextConfig = {
output: process.env.CAPACITOR_BUILD === ‘true’ ? ‘export’ : undefined,
skipTrailingSlashRedirect: true,
// No env section - was removed as suggested by support
};

export default nextConfig;Steps to Reproduce:

  1. Set SUPABASE_SERVICE_ROLE_KEY in Vercel dashboard (all environments enabled)
  2. Deploy to Vercel
  3. Call /api/test-env endpoint
  4. Observe that hasSupabaseServiceRoleKey: false

Troubleshooting Steps Already Taken:

  1. :white_check_mark: Verified variables are set in Vercel dashboard for all environments (Production, Preview, Development)
  2. :white_check_mark: Multiple redeployments performed (with and without build cache)
  3. :white_check_mark: Removed env section from next.config.ts (was suggested by support)
  4. :white_check_mark: Downgraded from Next.js 16 RC to stable Next.js 15.5.6
  5. :white_check_mark: Created test variable TEST_SERVICE_KEY to rule out name-specific issues
  6. :white_check_mark: Verified Route Handlers are correctly implemented (app/api/*/route.ts)

Project information (URL, framework, environment, project settings):

  • Project URL: https://neonarc.de
  • Framework: Next.js 15.5.6 (App Router)
  • React: 18.3.1
  • Deployment: Vercel Production
  • Environment: Production (VERCEL_ENV=production)
  • Route Handlers: app/api/*/route.ts structure
  • Variables Set in Dashboard:
    • NEXT_PUBLIC_SUPABASE_URL :white_check_mark: (works)
    • NEXT_PUBLIC_SUPABASE_ANON_KEY :white_check_mark: (works)
    • SUPABASE_SERVICE_ROLE_KEY :cross_mark: (doesn’t work)
    • TEST_SERVICE_KEY :cross_mark: (doesn’t work)

Impact:
This is blocking critical production functionality:

  • Player search API routes
  • Contact request management
  • User blocking/unblocking
  • Direct messaging

Question:
Has anyone else experienced this issue where ALL non-NEXT_PUBLIC_ environment variables are unavailable in Next.js Route Handlers on Vercel? Is there a project-specific setting or configuration that could be affecting this?

Any help or insights would be greatly appreciated!
Sascha