Can't access env vars in Workers build
I'm migrating some Astro projects, that build static pages, from Cloudflare Pages to Cloudflare Workers. I'm following the migration tutotial and looking the docs. But I 'cant access the environment variables defined in wrangler.toml in process.env during or after the build.
I using the compat flags:
compatibility_flags = [ "nodejs_compat", "nodejs_compat_populate_process_env" ]
But in any moment i'm seeing the variables in log
Is there anything else i need to do?10 Replies
Have you added those variables to
Settings > Build > Build Variables and Secrets
? Or do you mean they aren't present once deployedI added some secrets in the panel, in this path you mentioned.
But i have others vars that are defined in wrangler.toml
The secrets from panel appear in process.env, but the vars from wrangler.toml dont
To confirm, you are logging process.env during the build right, not against your deployed Worker?
Yes. I'm lookin in the Build history log
Yeah, that's expected. The variables in your
wrangler.toml
/jsonc
are the variables present on your deployed Worker. They wouldn't be available in the build environmentOhh. That's a bummer
In build time the only env vars present is the ones defined via panel?
Yes, that's correct
For example, if you have a build variable configuring the version of Node you need to build your project, it wouldn't make sense to add that to the deployed Worker, and vice versa
Thats makes sense. Is there another way to define build vars for workers, or only in the panel?
I think it is only via the panel right now?
Maybe the API?
Interesting. I will check this option
Thanks a lot!