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.envat runtime in API Routes SUPABASE_SERVICE_ROLE_KEYis not available (returnsundefined)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.envat runtime in API Routes SUPABASE_SERVICE_ROLE_KEYshould be accessible viaprocess.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:
- Set
SUPABASE_SERVICE_ROLE_KEYin Vercel dashboard (all environments enabled) - Deploy to Vercel
- Call
/api/test-envendpoint - Observe that
hasSupabaseServiceRoleKey: false
Troubleshooting Steps Already Taken:
- ✅ Verified variables are set in Vercel dashboard for all environments (Production, Preview, Development)
- ✅ Multiple redeployments performed (with and without build cache)
- ✅ Removed
envsection fromnext.config.ts(was suggested by support) - ✅ Downgraded from Next.js 16 RC to stable Next.js 15.5.6
- ✅ Created test variable
TEST_SERVICE_KEYto rule out name-specific issues - ✅ 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.tsstructure - Variables Set in Dashboard:
NEXT_PUBLIC_SUPABASE_URL✅ (works)NEXT_PUBLIC_SUPABASE_ANON_KEY✅ (works)SUPABASE_SERVICE_ROLE_KEY❌ (doesn’t work)TEST_SERVICE_KEY❌ (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