environment variables return undefined when i deploy

Hi. i'm trying to deploy my app locally but in the terminal where i'm logging the variables are returning undefined
baseURL: undefined,
baseApiURL: undefined,
baseWebURL: undefined,
dashboardURL: undefined,
gaTrackingID: undefined,
recaptchaPK: undefined
baseURL: undefined,
baseApiURL: undefined,
baseWebURL: undefined,
dashboardURL: undefined,
gaTrackingID: undefined,
recaptchaPK: undefined
in wrangler i have the variables like this
"env": {
"local": {
"name": "title",
"vars": {
"NEXT_PUBLIC_STAGE": "prod",
"NEXT_PUBLIC_GA_TRACKING_ID": "xxxx",
"NEXT_PUBLIC_RECAPTCHA_PK": "xxxxx",
"NEXT_PUBLIC_BASE_API_URL": "xxxx",
"NEXT_PUBLIC_BASE_WEB_URL": "xxxx",
"NEXT_PUBLIC_DASHBOARD_URL": "xxxx"
}
},
"staging": {
"name": "title",
"route": "xxxx.xx",
"zone_id": "xxxx",
"vars": {
"vars": {
"NEXT_PUBLIC_STAGE": "prod",
"NEXT_PUBLIC_GA_TRACKING_ID": "xxxx",
"NEXT_PUBLIC_RECAPTCHA_PK": "xxxxx",
"NEXT_PUBLIC_BASE_API_URL": "xxxx",
"NEXT_PUBLIC_BASE_WEB_URL": "xxxx",
"NEXT_PUBLIC_DASHBOARD_URL": "xxxx"
}
}
},
"production": {
"name": "xxxx",
"route": "xxxxx",
"zone_id": "xxxxx",
"vars": {
"NEXT_PUBLIC_STAGE": "prod",
"NEXT_PUBLIC_GA_TRACKING_ID": "xxxx",
"NEXT_PUBLIC_RECAPTCHA_PK": "xxxxx",
.....
}
}
}
"env": {
"local": {
"name": "title",
"vars": {
"NEXT_PUBLIC_STAGE": "prod",
"NEXT_PUBLIC_GA_TRACKING_ID": "xxxx",
"NEXT_PUBLIC_RECAPTCHA_PK": "xxxxx",
"NEXT_PUBLIC_BASE_API_URL": "xxxx",
"NEXT_PUBLIC_BASE_WEB_URL": "xxxx",
"NEXT_PUBLIC_DASHBOARD_URL": "xxxx"
}
},
"staging": {
"name": "title",
"route": "xxxx.xx",
"zone_id": "xxxx",
"vars": {
"vars": {
"NEXT_PUBLIC_STAGE": "prod",
"NEXT_PUBLIC_GA_TRACKING_ID": "xxxx",
"NEXT_PUBLIC_RECAPTCHA_PK": "xxxxx",
"NEXT_PUBLIC_BASE_API_URL": "xxxx",
"NEXT_PUBLIC_BASE_WEB_URL": "xxxx",
"NEXT_PUBLIC_DASHBOARD_URL": "xxxx"
}
}
},
"production": {
"name": "xxxx",
"route": "xxxxx",
"zone_id": "xxxxx",
"vars": {
"NEXT_PUBLIC_STAGE": "prod",
"NEXT_PUBLIC_GA_TRACKING_ID": "xxxx",
"NEXT_PUBLIC_RECAPTCHA_PK": "xxxxx",
.....
}
}
}
i'm logging the envoirment variables like this
console.log('NEXT_PUBLIC_RECAPTCHA_PK:', process.env.NEXT_PUBLIC_RECAPTCHA_PK);
console.log('BASE_API_URL:', process.env.BASE_API_URL);
console.log('NEXT_PUBLIC_RECAPTCHA_PK:', process.env.NEXT_PUBLIC_RECAPTCHA_PK);
console.log('BASE_API_URL:', process.env.BASE_API_URL);
can anyone help me with this. am i doing something wrong? these are the commands in package.json & i'm executing this one -> "deploy:worker": "npm run build:worker && wrangler deploy"
"build": "next build",
"build:worker": "opennextjs-cloudflare",
"dev:worker": "wrangler dev -e development --port 8001",
"preview:worker": "npm run build:worker && npm run dev:worker",
"deploy:worker": "npm run build:worker && wrangler deploy"
"build": "next build",
"build:worker": "opennextjs-cloudflare",
"dev:worker": "wrangler dev -e development --port 8001",
"preview:worker": "npm run build:worker && npm run dev:worker",
"deploy:worker": "npm run build:worker && wrangler deploy"
No description
2 Replies
Hurby
Hurby2w ago
@Rohil use .dev.vars in the local development
Hurby
Hurby2w ago
Cloudflare Docs
Environment variables · Cloudflare Workers docs
Environment variables are a type of binding that allow you to attach text strings or JSON values to your Worker

Did you find this page helpful?