What is the error number?
10021
What is the error message?
Uncaught TypeError: Main module name is not present in bundle.\n
What is the issue or error you’re encountering
I’m trying to use the “Upload worker module” API route, but I always have the same error
What steps have you taken to resolve the issue?
Hello
I’m trying to use this API route to upload a worker with metadata.
I’m using Node.js and Axios, with the following code:
const api = axios.create({
baseURL: 'https://api.cloudflare.com/client/v4',
headers: {
Authorization: `Bearer ${myToken}`,
'Content-Type': 'multipart/form-data',
},
})
const workerCode = `export default {
async fetch(request, env, ctx) {
return new Response("Hello World!");
},
};`
const form = new FormData();
form.append('main.js', workerCode);
form.append(
'metadata',
JSON.stringify({
main_module: 'main.js',
compatibility_date: '2025-02-04',
compatibility_flags: ['nodejs_compat'],
})
);
await api.put(
`/accounts/${accountId}/workers/scripts/${workerName}`,
form
);
The error message is always the same:
Uncaught TypeError: Main module name is not present in bundle
Copy-pasting the worker code manually in the Cloudflare Dashboard works.
What am I missing? I cannot find any example in the documentation, but I carefully read the API docs and I cannot make it work
Thanks a lot for your help