Cloudflare Workers "No event handlers were registered" in CI
A Worker must register at least one handler: an export default { fetch } for the modules format, or an addEventListener("fetch", ...) for the service-worker format. If wrangler finds neither, it reports the script does nothing and stops.
What this error means
wrangler deploy or wrangler dev fails with "No event handlers were registered. This script does nothing." The entry file exported nothing usable as a Worker entrypoint.
✘ [ERROR] No event handlers were registered. This script does nothing.Common causes
The entrypoint has no default export
In the modules format the file must export default an object with a fetch (or scheduled, queue) method. A bare script with no default export registers nothing.
The main field points at the wrong file
wrangler.toml main points to a file that is not the handler module (a config or barrel file), so the deployed entry exposes no handler.
How to fix it
Export a default handler object
- Define
export default { fetch(request, env, ctx) { ... } }in the entry module. - Point
mainin wrangler.toml at that file. - Re-run wrangler dev to confirm the handler is detected.
export default {
async fetch(request, env, ctx) {
return new Response('ok');
},
};Fix the entrypoint path
Make sure wrangler.toml main resolves to the module that exports the handler, not a re-export or config file.
# wrangler.toml
main = "src/index.js"How to prevent it
- Keep the handler export in the file referenced by main.
- Use the modules format with a default export for new Workers.
- Run wrangler dev locally before pushing to catch a missing handler.