Cloudflare Workers "Script startup exceeded CPU time limit" in CI
When a Worker is uploaded, Cloudflare runs its top-level code once to validate it. If that startup work exceeds the CPU budget, the deploy is rejected with "Script startup exceeded CPU time limit".
What this error means
A wrangler deploy step fails with "Script startup exceeded CPU time limit." and the Worker is not published.
Wrangler
✘ [ERROR] A request to the Cloudflare API failed.
Script startup exceeded CPU time limit.Common causes
Heavy work at module top level
Parsing large data, building big structures, or running expensive setup as the module loads consumes the startup CPU budget.
A large or unoptimized bundle
A big bundle takes longer to parse and initialize, which counts toward the startup limit measured during validation.
How to fix it
Defer initialization to the first request
- Identify top-level work that runs as the module loads.
- Move it into the
fetchhandler and memoize so it runs once per isolate. - Redeploy and confirm validation passes.
src/index.js
let cache;
export default {
async fetch(req, env) {
cache ??= await loadConfig(env);
return respond(req, cache);
}
};Shrink the bundle
Remove large dependencies and split heavy data out of the bundle so startup parsing stays within budget.
How to prevent it
- Keep top-level module code light; defer setup to the handler.
- Avoid embedding large data blobs in the bundle.
- Profile the bundle size before deploying.
Related guides
Cloudflare Wrangler "Cannot find project" (Pages) in CIFix Cloudflare Wrangler "Error: Cannot find project" in CI - the Pages project name passed to wrangler pages…
Cloudflare Workers "binding is not defined" in CIFix Cloudflare Workers runtime "ReferenceError: X is not defined" after deploy in CI - a KV, R2, D1, or env b…
Vercel "Function Payload Size exceeds" limit in CIFix Vercel "Error: The Serverless Function ... exceeds the maximum size limit" in CI - a bundled function plu…