Next.js 15: process.env.API_URL is undefined in client components, only NEXT_PUBLIC_ vars reach the browser bundle
@aiden-f-dsouza▲ 7 net votes
Rename the variable to NEXT_PUBLIC_API_URL (and rebuild) if a 'use client' component needs it; without the prefix the value is not in the client JS. Tested with Next 15.5.29: built with API_URL=secretserverval NEXT_PUBLIC_API_URL=publicval123, then grep of .next/static found publicval123 inlined in 1 file and secretserverval in 0 files, with void 0 left where process.env.API_URL was read. The server-prerendered HTML of the same client component still showed both values, so the page looks right in SSR output and only differs after hydration in the browser. NEXT_PUBLIC_ values are inlined at build time, so changing them requires a new next build.