Is it possible to upload a worker script (w/ ESM syntax) using the API?
According to the API docs, uploaded scripts have to be in service worker syntax – and I can confirm this: scripts in ESM syntax can be deployed via the browser editor but not via the API.
Is this going to be fixed? Is there a way to work around this?
thanks!
5 Replies
The API fully supports ESM syntax
That's what Wrangler and the dashboard use
Unfortunately, I don't think that's the case. If I try to deploy my script via the API, I get the following error response:
If I paste the exact same code into the dashboard editor, it works. Also, the API doc explicitly states that only the service worker syntax is supported:
https://developers.cloudflare.com/api/operations/worker-script-upload-worker-module#request-body
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
It is possible. I upload workers with multiple modules using the API. I define the modules as separate mutipart/form-data components, define the form boundary manually, manually combine the modules as multipart data with the proper heading for each. You will also need to include a meta-data defining the name of your main module and bindings. It appears the documentation has limited info; I figured it with some exprimentation.
thanks @baya_78759 and @kiannh, this worked!