Worker deploys fine via Wrangler and Web UI but fails via API with SyntaxError
Hi everyone. I'm having a rather odd issue. I'm trying to deploy a worker (I'm using Workers for Platforms but it shouldn't matter) and while it's able to deploy perfectly fine using Wrangler and Web UI, when I deploy via the API, I'm getting a syntax error.
Uncaught SyntaxError: Unexpected token 'export'
It seems the API will not accept ES module syntax for some reason?
Reproduces even with Cloudflare's Hello World example:
My API code:
The multipart stuff is 100% correct and the worker uploads since the error i'm getting shows the exact location of the word export
in the code, so the issue is at the deployment stage inside Cloudflare's API
Any tips to fix it would be much appreciated!
Thanks!3 Replies
content-type should be
application/javascript+module
If you update the content-type this should work but let me know if it doesn't
This code works - changes:
* application/javascript
-> application/javascript+module
* Changed Blob
to File
and added the filename worker.js
- this is needed for the main part to be recognised
Sorry for the confusion here - we'll improve the docs around thisDeployed succesfuly
Thanks! 🙌🏻
Yeah I don't think i've seen this in the docs
Halfway through debugging I had a hope that maybe
cloudflare
Node package would help but that isn't super documented either 😄
Either way, thanks for the help 🙏🏻yeah our docs are lacking on the actual content upload part which can be the most confusing at times - we'll fix that asap!