Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › Cloudflare Workers

How to Fix “Script Startup Exceeded CPU Time Limit” in a Next.js Cloudflare Worker

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

If a Next.js deployment reports “Script startup exceeded CPU time limit”, the immediate fix is to reduce or relocate work that runs while the Worker module is loading. Cloudflare gives that startup validation failure a different identifier, 10021; Error 1102 is a runtime response returned when an already-deployed Worker exceeds its per-request CPU allowance. Treating the two as the same problem sends you to the wrong logs and settings. For startup validation, measure the rejected deployment with Wrangler, inspect the generated CPU profile, then move expensive top-level initialization into the request handler or into the build process. The official Cloudflare documentation does not identify a particular Next.js adapter or version as the cause, so your profile and generated bundle—not a blanket framework upgrade—must determine the change.

What does “Script startup exceeded CPU time limit” mean on Cloudflare Workers?

It means Cloudflare could not load and execute your Worker’s global (top-level) code within its startup budget. This happens during deployment validation, before the handler is available to receive a request. Cloudflare documents the message as validation error 10021, not as the runtime Error 1102 response. See Cloudflare’s Errors and exceptions documentation and the Workers limits page (updated October 12 and October 15, 2026).

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The startup budget is one second of CPU time for parsing and executing global scope. Global scope is everything outside your request handlers: imports, module initialization, generated data structures, and other code that executes as the bundle is loaded. Waiting for a network response is not CPU time, but synchronous parsing, computation, and object construction during loading are.

Cloudflare’s example is generating or consuming a large schema at top level. A large generated bundle can also increase parsing and initialization cost. The practical question is therefore not “Which Next.js setting fixes 1102?” but “What does this particular Worker execute before its handler starts?”

Popular on Amazon
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

How is startup validation different from runtime Error 1102?

Check the stage and identifier first. A deployment rejection points to startup validation; a response from a deployed Worker points to request-time CPU exhaustion.

Diagnostic Startup validation Runtime CPU exhaustion
When it occurs During deployment validation, before requests are handled During an invocation of a deployed Worker
Cloudflare identifier Validation error 10021 Error 1102
Code measured Parsing and executing top-level/global-scope code CPU used while handling a request
Primary remedy Reduce startup work or move it into a handler or the build step Profile and optimize request work; adjust the runtime allowance where appropriate

Cloudflare defines 1102 as a Worker exceeding its CPU time limit in its Error 1102 guidance. That page is useful when the error appears in an HTTP response or invocation log. It is not the right explanation for a deployment rejected with the startup wording.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cloudflare also notes that CPU time measures time spent executing Worker code; time spent waiting on network requests does not count. That distinction matters for a runtime investigation, while startup validation is initially about code executed during module loading.

Why can a Next.js Worker fail before its handler runs?

A Next.js build for Workers can produce a substantial server bundle. When that bundle is loaded, every imported module’s top-level statements may run before the adapter’s handler is called. Expensive initialization, large generated objects, and parsing-heavy data therefore consume the one-second startup budget even if a particular route is never requested.

Do not assume that the framework or one named adapter is automatically responsible. The official Cloudflare sources establish the platform limit and profiling tools, but they do not name a Next.js adapter, Next.js release, or adapter option that universally fixes validation error 10021. Different adapters and build outputs can place different code in global scope. Use the rejected deployment’s profile to identify the actual module and operation.

Typical places to inspect in the generated Worker

  • Imports that construct large registries, schemas, or lookup objects immediately.
  • Top-level calls that parse or transform substantial data.
  • Generated code that causes a large bundle to be parsed and initialized before routing begins.
  • Initialization that is needed only for one route but is loaded for every isolate.

These are investigation categories, not proof that a specific Next.js package is faulty. The CPU profile and the output produced by your adapter are the evidence for a project-specific diagnosis.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Also popular on Amazon
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

How do I measure the startup failure with Wrangler?

Let Wrangler report the rejected startup rather than guessing from the size of your source tree. Cloudflare says a rejected deployment includes a startup_time_ms value and that Wrangler automatically generates a CPU profile for a deployment that exceeds startup time.

  1. Reproduce the deployment validation failure. Run the Wrangler deploy or versions-upload workflow configured for your Worker. In a project whose deploy script uses the standard command, that may be npx wrangler deploy; use the command your repository already uses so the same Next.js build output is tested.
  2. Record startup_time_ms. Treat the value as a measurement of the rejected Worker’s startup path, not as a request-latency benchmark. Keep it with the commit and build configuration that produced it.
  3. Open the generated CPU profile. Wrangler’s rejection output identifies the profile or its location. Expand the call tree until you can distinguish parsing, module initialization, and the particular top-level function doing the work.
  4. Run the documented startup check when needed. Cloudflare refers developers to wrangler check startup for additional startup details. Use the command supported by the Wrangler version installed in your project and read its output alongside the deployment profile.
  5. Change one startup contributor and redeploy. A lower startup_time_ms after a targeted change is stronger evidence than a general dependency upgrade. Keep the profile from the failing build so you can verify that the expensive path disappeared rather than merely moved.

The profile should answer two questions: which code executes before the handler, and how much of the startup budget it consumes. If the profile does not implicate a suspected package, do not label that package the cause.

What code should I move out of global scope?

Move work that is not required for every isolate to the narrowest safe location. Cloudflare’s documented remedy is to avoid expensive work in global scope and move initialization into the handler or to build time.

Move request-specific initialization into the handler

If a value depends on the request, route, tenant, or rarely used feature, create it inside the relevant handler branch. This prevents every Worker startup from paying for work that only some requests need. Reuse the result within that request where possible, but verify runtime CPU separately after the move.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
// Before: runs while the Worker module is loading
const schema = buildLargeSchema();

export default {
  async fetch(request, env, ctx) {
    return handleRequest(request, schema, env);
  }
};

// After: initialization is performed only when this route needs it
export default {
  async fetch(request, env, ctx) {
    const schema = buildLargeSchema();
    return handleRequest(request, schema, env);
  }
};

This example illustrates placement, not a required Next.js API. If the schema is identical for every request, moving it may trade startup CPU for request CPU; measure that trade-off and consider build-time generation instead.

Generate static data at build time

When the data can be determined from source or configuration during the Next.js build, generate the compact representation before deployment. The Worker then loads the result rather than constructing it at runtime startup. Confirm that the generated artifact is actually included in the Worker bundle you deploy and that its parsing cost is acceptable.

Also popular on Amazon
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Reduce what the Worker must parse

Use the profile and bundle output to find code that is loaded globally but needed by only one path. Remove unused initialization, defer route-specific imports where the adapter supports that pattern, and avoid shipping redundant generated data. These changes are conditional on your adapter’s build semantics; validate the resulting Worker rather than assuming a browser-style split will apply unchanged.

Can increasing the Workers CPU limit fix the startup error?

Not according to the documented limits. Cloudflare lists the one-second startup requirement separately from the per-request CPU allowance, so raising a paid plan’s runtime CPU setting is not documented as raising the startup budget. Fix startup validation by changing the code that runs during loading.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Limit Documented value What it applies to
Startup CPU 1 second Parsing and executing global scope before the handler
Workers Free request CPU 10 ms CPU used by each request on the Free plan
Workers Paid request CPU 30 seconds default; configurable up to 5 minutes CPU used by each request on the Paid plan
Isolate memory 128 MB Memory available to an isolate; startup-memory validation is a separate failure

Cloudflare’s limits page also says the average Worker uses approximately 2.2 ms of CPU per request. That is a platform-wide contextual figure, not an expected measurement for your Next.js startup or route.

What should I do if the deployed app returns Error 1102 instead?

If deployment succeeds but a request returns 1102, switch to a runtime investigation. Capture the failing route, input size, and invocation logs, then profile representative request behavior rather than the deployment startup path.

  • Reduce unnecessary loop iterations and avoid repeatedly doing the same computation.
  • Optimize JSON parsing and transformation when large payloads are involved.
  • Cache computed values when their inputs and freshness requirements permit it.
  • Break a large operation into smaller chunks or separate requests when the application can preserve correctness that way.
  • On Workers Paid, consider a higher per-request CPU allowance only after profiling shows that the work is legitimate runtime processing. This setting does not change the one-second startup validation budget.

Do not apply these runtime tactics as a substitute for fixing validation error 10021. A Worker that cannot pass startup validation never reaches request handling.

How can I profile a representative Next.js request locally?

Cloudflare’s CPU-profiling guidance describes using wrangler dev with browser DevTools. Local results are useful for locating hot functions, but production behavior can be difficult to reproduce unless the routes, request volume, data sizes, and invocation patterns are representative.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Also popular on Amazon
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  1. Build the same Worker output that your deployment pipeline uploads.
  2. Start the local Worker with wrangler dev.
  3. Exercise the exact Next.js route and payload that exhibits the problem, including cold-start conditions when possible.
  4. Record a CPU profile in DevTools and separate module-loading work from handler work.
  5. Compare the local call tree with Wrangler’s rejected-startup profile or production invocation data. Treat local timings as directional when the isolate, traffic, or data differs.

For production observability, Cloudflare also provides metrics and analytics. Use those metrics to establish whether the symptom is deployment rejection, a route-specific runtime spike, or a broader traffic pattern before changing code.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What are the most common failed fixes?

Changing the plan before measuring

A paid runtime allowance addresses request CPU, not the separately documented startup validation budget. Plan changes can add cost without changing the code path that causes 10021.

Assuming every 1102 message is a startup problem

An HTTP 1102 response from a live Worker is evidence of runtime exhaustion. Search deployment output for validation error 10021 and startup timing instead of applying deployment-only advice to a request failure.

Blaming a Next.js version without a profile

The cited Cloudflare documentation does not establish a universal adapter, version, or configuration culprit. Upgrade or reconfigure only when your generated bundle and profile show why that change removes the expensive initialization.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Moving work into the handler without checking request CPU

Relocation can make deployment pass while making a route slower or causing runtime 1102. Re-profile the affected request after each relocation, and build static data ahead of time when that is compatible with the application.

Testing a different bundle than the one deployed

Next.js build settings, environment variables, and adapter output can change the Worker substantially. Reproduce the failure with the same build and Wrangler upload path used in deployment; otherwise a successful local check may describe a different artifact.

Also popular on Amazon
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

What is the fastest remediation checklist?

  • Classify the symptom: deployment rejection with startup wording, or runtime HTTP 1102.
  • For startup validation, capture startup_time_ms and Wrangler’s CPU profile.
  • Identify top-level functions, large schemas, generated data, and parsing work before the handler.
  • Move request-specific work into the handler and deterministic generation into the build step.
  • Reduce globally loaded code only where the adapter’s output and profile support the change.
  • Redeploy the same artifact and verify that startup validation succeeds.
  • If requests then hit 1102, profile those requests independently and optimize their CPU use or evaluate the documented paid runtime allowance.

Cloudflare’s current documentation is clear on the boundary: global scope must parse and execute within one second, while request CPU has separate plan-specific limits. A successful fix is therefore a measured change to the code executed at the failing stage, not a generic Next.js or plan change.

Where can I verify the limits and error definitions?

Use Cloudflare’s primary documentation for the current wording and platform values: Workers Limits (updated October 12, 2026), Errors and exceptions (updated October 15, 2026), Error 1102, and Profiling CPU usage (updated October 8, 2026). These pages describe platform behavior and tooling; they do not promise a framework-specific fix for every Next.js deployment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Does a larger Next.js bundle always cause Cloudflare startup error 10021?

No. Cloudflare identifies large bundles as one factor that can increase startup work, but bundle size alone does not prove the cause. The rejected deployment’s startup timing and CPU profile show whether parsing or a particular top-level initializer is responsible.

Will lazy loading eliminate Worker startup CPU usage?

Only if the resulting adapter output actually defers that code until after the handler starts. Verify the generated Worker and profile; a source-level dynamic import does not by itself guarantee a smaller global-scope path in every Next.js-on-Workers build.

Can I keep a large schema in a global variable after moving its construction?

You can cache an initialized value when the platform and application semantics allow it, but the first construction still has to occur somewhere. Measure both cold-start validation and request CPU, and ensure the cache does not depend on request-specific data.

What information should I include when asking for help with this error?

Include whether the failure occurs during deployment or invocation, the exact Cloudflare identifier, the reported startup_time_ms if present, the Wrangler profile, and the adapter/build configuration that produced the artifact. Remove secrets and private request data before sharing logs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Cloudflare WorkersCPU limitsError 10021Error 1102Next.jsTroubleshootingWrangler

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.