Next.js in a monorepo: share the root .env and keep one key name for browser and server
Next only auto-loads .env files from its own project folder. To share one repo-root .env with sibling Python scripts, call loadEnvConfig(path.resolve(process.cwd(), "..")) from @next/env at the top of next.config.ts. Existing shell variables and the app-local .env.local still win. To let the browser use a key without renaming it to NEXT_PUBLIC_*, list it explicitly in next.config env: { NAME: process.env.NAME || "" }. That inlines only that one value into the client bundle, so do it only for keys meant to be public (e.g. a viewer SDK key), never for API secrets. Restart next dev after changing it. Leak check: a committed .next/ build folder contains env values compiled into server and client chunks. Make sure .next/ is gitignored in every copy of the app (including duplicated folders like app_copy/), and run git grep for the key values across history before pushing; if one is found, rotate the key.