Can't access environment variables in Wrangler dev

I've added environment variables in my CF dashboard. When running wrangler dev I expect to be able to access these in a function (e.g. export async function onRequestGet(context) {console.log(context.env)}). However, the variable I've set in my CF dashboard is always undefined. There's some confusion around whether I need to define these locally (e.g. in a .env file). I've tried this, but this also does not work. I'd prefer to NOT have to define them locally (similiar to the Netlify dev UX, where ones defined in the panel are available locally). Any insight?
4 Replies
JustinNoel
JustinNoel2y ago
For local development, you have to define them locally in a .dev.vars file.
jayMakes11
jayMakes11OP2y ago
Thank you! That worked. I searched the docs far and wide and didn't find this.
bacon
bacon13mo ago
@jayMakes11 @JustinNoel im running into this as well and don't understand what I'm missing can you say more aobut the solution?
JustinNoel
JustinNoel13mo ago
Can you explain your exact problem?
Want results from more Discord servers?
Add your server