#Is it possible to upload a worker script (w/ ESM syntax) using the API?
6 messages · Page 1 of 1 (latest)
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:
{
result: null,
success: false,
errors: [
{
code: 10021,
message: "Uncaught SyntaxError: Unexpected token 'export'\n at worker.js:432\n"
}
],
messages: []
}
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
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.