Error 1101: Worker threw exception
Your Cloudflare Worker hit a JavaScript error while handling the request, so Cloudflare showed its error page in place of a response.
Also appears as
- error code: 1101
Prompt to fix it
My Cloudflare Worker returns "Error 1101: Worker threw exception". Help me find the exception: tell me to run npx wrangler tail and paste what it prints, or check Workers Logs. Then fix the root cause in the code. Compare the bindings and secrets the code uses (env.*) with what the Wrangler config and deployed secrets provide, check for Node.js APIs that need the nodejs_compat flag, and make sure every awaited call handles failure. Add a top-level try/catch that logs the error and returns a 500, without hiding the original error.
Paste into Layerwise or any AI coding tool.
What it means
A Worker is code that runs on Cloudflare’s servers for each request. Error 1101 means that code threw an exception nothing caught, so it never returned a response. The page tells visitors nothing about the cause; the details are in your Worker’s logs.
Most 1101s come from differences between your machine and production. A secret or binding (a database, KV namespace, or R2 bucket) exists locally but isn’t set on the deployed Worker, so env.DB or env.API_KEY is undefined. Node.js APIs like Buffer also fail unless the nodejs_compat compatibility flag is on.
A related log message, “The script will never generate a response,” also ends in 1101. It means a promise the response depended on never finished, so the runtime stopped waiting.
Common causes
- A secret or binding is missing on the deployed Worker, so the code reads a property of
undefined. - An awaited
fetchor database call fails, and notry/catchhandles it. - The code uses a Node.js API without the
nodejs_compatcompatibility flag. - A promise the response depends on never resolves or rejects.
How to fix it
- Run
npx wrangler tailin the project, reload the failing page, and read the exception and stack trace it prints. - Or open Workers & Pages → your Worker → Logs in the Cloudflare dashboard. If it’s empty, turn on Workers Logs with
"observability": { "enabled": true }in your Wrangler config. - Compare secrets and bindings:
npx wrangler secret listshows the deployed secrets, and the Wrangler config must declare every binding the code uses. - Fix the failing line, redeploy with
npx wrangler deploy, and keepwrangler tailrunning to confirm. - Wrap the handler in a
try/catchthat logs the error and returns a500, so future failures leave a clear trail.
Example fix
export default {
async fetch(request, env, ctx): Promise<Response> {
try {
// `await` keeps async failures inside this try block.
return await handleRequest(request, env, ctx);
} catch (err) {
// Shows up in `wrangler tail` and Workers Logs.
console.error(err);
return new Response('Something went wrong', { status: 500 });
}
}
} satisfies ExportedHandler<Env>;Related errors
All errorsError 522: Connection timed out
Cloudflare couldn’t open a connection to the server behind your site in time, so it showed its own error page in place of your app.
Cannot read properties of undefined
The code asked for a property of a value that doesn’t exist yet, usually data that hasn’t loaded or a field the API didn’t return.
X is not defined
The code used a name JavaScript can’t find anywhere, usually because of a missing import, a typo, or a Node-only global like process in the browser.
500 Internal Server Error
The server’s code threw an error or crashed while handling the request, and the real error message is waiting in the server logs.
Build with an agent that checks its work
The Layerwise agent clicks through the live preview and reads the console, so it catches errors before you do.