michelle
CDCloudflare Developers
•Created by michelle on 5/22/2024 in #workers-help
Env Vars in Worker
Thank you for your help!
I found the issue (in case anyone stumbles upon this thread later).
It seems that my Worker was a 'Service Worker' but 'ES Modules' are the new and preferred Workers format. I don't know if there is a way to toggle this in the dashboard, but there seems to be a way to toggle it in wrangler files. Using the Service Worker version, env vars can be called directly (without the env. prefix).
This article discusses it in more detail:
https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
11 replies
CDCloudflare Developers
•Created by michelle on 5/22/2024 in #workers-help
Env Vars in Worker
Trying this now! Why do you think the export isn't working with my current Worker though?
11 replies
CDCloudflare Developers
•Created by michelle on 5/22/2024 in #workers-help
Env Vars in Worker
Also using the dashboard to set the environment variables
11 replies
CDCloudflare Developers
•Created by michelle on 5/22/2024 in #workers-help
Env Vars in Worker
Yes
11 replies
CDCloudflare Developers
•Created by michelle on 5/22/2024 in #workers-help
Env Vars in Worker
I am new to Cloudflare so forgive me if this is obvious, but whenever I use 'export default' in my worker.js file it gives me this error:
"Uncaught SyntaxError: Unexpected token 'export' at worker.js:1 (Code: 10021)"
I can't figure out what I am missing, because in all their Worker documentation code examples they use examples with 'export default'.
11 replies