Hi, scratching my head a bit.
Building out based on the Vercel Turborepo Next template. I have a few custome environment variable and want to make use of the system ones like VERVEL_URL etc.
I have a .env.local file for local dev, and setting the vars in the Dashboard for deployed envs.
Disable and re-enabled the “Automatically expose System Environment Variables”
The build log was Warning that the envs were not allows in turborepo so added them to the "globalEnv" array. Warnings now gone. But vars still not showing up in the deployed build.
I’ve set up some console logs which work locally.
But deployed they return undefined
// turbo.json
{
"$schema": "https://turborepo.com/schema.json",
"ui": "tui",
"globalEnv": [
"VERCEL_URL",
"VERCEL_ENV",
"VERCEL_BRANCH_URL",
"STYTCH_PROJECT_ID",
"STYTCH_PUBLIC_TOKEN"
],
"tasks": {
"build": {
"dependsOn": ["^build"],
"inputs": ["$TURBO_DEFAULT$", ".env*"],
"outputs": [".next/**", "!.next/cache/**"],
// are these needed?
"env": [
"VERCEL_URL",
"VERCEL_ENV",
"VERCEL_BRANCH_URL",
"STYTCH_PROJECT_ID",
"STYTCH_PUBLIC_TOKEN"
]
},
// .env.local
# General vars
NEXT_PUBLIC_BASE_URL=http://localhost:3001
# Stytch Auth
# The below values may be found in your Stytch Dashboard: https://stytch.com/dashboard
NEXT_PUBLIC_STYTCH_PROJECT_ENV=test
NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN=public-token-test-xxxxxxxxxxxxxxx
...
Lib function to return the base URL
export function getBaseUrl(): string {
console.log("process.env.VERCEL_URL", process.env.VERCEL_URL);
console.log(
"process.env.NEXT_PUBLIC_BASE_URL",
process.env.NEXT_PUBLIC_BASE_URL,
);
console.log("process.env.VERCEL_ENV", process.env.VERCEL_ENV);
console.log("process.env.VERCEL_BRANCH_URL", process.env.VERCEL_BRANCH_URL);
// cats
if (process.env.VERCEL_BRANCH_URL) {
return `https://${process.env.VERCEL_BRANCH_URL}`;
}
if (process.env.VERCEL_URL) {
return `https://${process.env.VERCEL_URL}`;
}
return process.env.NEXT_PUBLIC_BASE_URL || "";
}
Deployed, check console: https://member-git-basic-partner-dash-onfire-health.vercel.app/login
“next”: “^15.3.0”,
“react”: “^19.1.0”,
“turbo”: “^2.5.4”,
“node”: “>=18”
“packageManager”: “bun@1.2.18”,


