The doc says: "any vars key are exposed as global variables", but they are not
I want to define something like DEV=true to detect dev mode (followed by some different initiating path), but access variable "DEV" in top level code just cause: "ReferenceError: DEV is not defined".
Is this a misunderstanding of the doc? I'm confused, the doc is in https://developers.cloudflare.com/workers/wrangler/environments/#staging-and-production-environments
Cloudflare Docs
Environments · Cloudflare Workers docs
Deploy the same Worker application with different configuration for each environment.
9 Replies
i think that'd be
env.ENVIRONMENT
indeed ^ will make sure the docs are updated
I'm using different key than the example, and the env variable does not exist outside fetch function
i see
my problem still remains though...
seems no eazy way to detect dev mode in the init time
tried the "define" option in wrangler, but it didn't substitute the target string in my main.ts. What's the target files this option tries to substitute? info missing in the doc. @Walshy | Workers/Pages
best way for you to do this is the env var you were doing before
this is how i do it in hono: https://github.com/WalshyDev/blob-builds/blob/main/worker/src/handlers/all.ts#L13-L14
middleware and just set based on env
thanks, I'll try
the "define" options do global replacements using esbuild. It should work, but the format is a little funky. How were you calling it?
and also that assumes you are not doing a custom build
thanks, i changed the define format in wrangler.toml and it works
for users searching for similar issues later, I post the define format here.
and the dev command: wrangler dev --define $$IS_DEV$$:true