On this page
What this issue is
Modern sites built with React, Next.js, Vue, Angular or similar tools split their JavaScript into chunks. A chunk is a small file that loads only when a visitor needs a certain page or component, for example the checkout or a booking form. This is called lazy loading.
A ChunkLoadError is thrown by webpack when that file cannot be loaded. Typical messages are ChunkLoadError: Loading chunk 123 failed and Loading CSS chunk failed. Vite and native ES modules show a similar message: Failed to fetch dynamically imported module. The cause is different from a normal script bug: the code is fine, but the file is missing, blocked or wrong.
Why it costs you leads or sales
The failing chunk is often the one behind the page that matters: the lead form, the cart, the checkout or a booking widget. The visitor clicks a link, nothing renders and they leave. Your ads and analytics usually still count the earlier page view, so traffic looks healthy while conversions drop.
It can also hit only some visitors, such as people who had a tab open during a deploy, people behind a certain network or those served by one CDN location. That makes it easy to miss in manual testing.
- Ad clickVisitor lands on the site
- Landing pageMain bundle loads fine
- Click to checkoutRoute chunk request fails (404 or blocked)
- Form or checkoutNever renders
- ConversionNo lead, no sale, no tracking hit
The landing page works, but the lazy route's chunk fails, so every later step is lost.
Example: a site that normally gets 40 leads a day drops sharply after a deploy leaves a route chunk unreachable.
How to check if your site has it
Open the page and the browser console
In Chrome press F12, open the Console tab and reload. Then click through to the lazy route (checkout, form, booking page). Look for ChunkLoadError or Failed to fetch dynamically imported module.
Check the Network tab
Filter by JS. Find the red request for the chunk file. Note the status (404, 403, 5xx, blocked) and the full URL it tried to load.
Compare the URL with your live files
Open the failing URL directly. A 404 means the file no longer exists. An HTML page returned instead of JavaScript means a rewrite rule or CDN is serving the wrong thing.
Test with a cold cache
Use a private window, then test again on mobile data. Try a tab that was opened before your last deploy, since that is the classic trigger.
| What you see | Likely cause |
|---|---|
| 404 on a hashed file like 123.a1b2c3.js | Old chunk deleted by a deploy while cached HTML still points to it |
| 200 but content is HTML | Rewrite or single-page-app fallback serving index.html for a missing JS file |
| Request goes to the wrong domain or path | Wrong publicPath, assetPrefix or base setting |
| Blocked by CORS or CSP | CDN on another domain without the right headers or policy |
| Timeout or 5xx | CDN or origin problem, or a flaky network |
How to fix it
The right fix depends on the cause you found. Work through these steps in order.
Keep old chunks available after a deploy
Do not delete the previous build's static files straight away. Keep them for at least a few days so open tabs and cached pages can still load them. Many hosts do this with immutable, versioned asset folders.
Fix the public path
Make sure the asset base matches where files really live: output.publicPath in webpack, assetPrefix in Next.js, base in Vite. A missing trailing slash or a wrong CDN domain is a common mistake.
Set correct caching
Serve HTML with a short cache or no-cache so it always points to current chunks. Serve hashed JS and CSS files with a long immutable cache. Purge the CDN after each deploy.
Stop the SPA fallback hijacking missing files
Make sure requests for .js and .css files return a real 404 when missing, not index.html. A missing file is then clear instead of causing a confusing syntax error.
Add a retry and a safe fallback
Retry the import once or twice, then reload the page once to pick up the new build. Show a clear message with a link if it still fails. See the snippet below.
import { lazy } from 'react';
function lazyWithRetry(factory) {
return lazy(async () => {
const key = 'chunk-reloaded';
try {
const mod = await factory();
sessionStorage.removeItem(key);
return mod;
} catch (err) {
if (!sessionStorage.getItem(key)) {
sessionStorage.setItem(key, '1');
window.location.reload();
return new Promise(() => {});
}
throw err;
}
});
}
const Checkout = lazyWithRetry(() => import('./Checkout'));Set the asset path
webpack: output.publicPath. Next.js: assetPrefix in next.config.js. Vite: base in vite.config.js. Rebuild and redeploy.
Keep old builds
Change your deploy script so it adds new files without removing the previous build's hashed assets immediately.
Fix cache headers
Set Cache-Control: no-cache on HTML and public, max-age=31536000, immutable on hashed assets.
Find the plugin or theme loading the chunk
The failing URL in the Network tab shows the folder, such as wp-content/plugins/name. Update that plugin or theme, since a partial update often leaves chunks missing.
Clear every cache layer
Purge your caching plugin, server cache and CDN. Disable JavaScript minify or combine options for that plugin to test whether they break the file path.
Check custom code and hosted scripts
If you load a bundled app from your own host in Project Settings > Custom Code, confirm the script URLs still exist after publishing the app. Republish the Webflow site to refresh references.
Check Custom HTML tags that load app bundles
If a tag injects a script from a build folder, update the URL to the current file or use a stable, unhashed entry file.
How to confirm it's fixed
- The lazy route renders in a private window with an empty cache
- No ChunkLoadError or failed dynamic import in the console
- Every JS and CSS request returns 200 with the correct content type
- A tab opened before the deploy still loads the route or reloads cleanly once
- The form or checkout can be completed and the tracking hits fire
How to prevent it happening again
10:00
A visitor loads the site. The HTML points to chunk 123.a1b2.js.
10:05
You deploy a new build. Old files are deleted.
10:06
The visitor clicks to checkout. The browser requests the deleted chunk and gets a 404.
10:07
ChunkLoadError. The page stays blank and the visitor leaves.
After fix
Old chunks are kept and a one-time reload fallback recovers open tabs.
- Keep previous build assets for several days after each deploy
- Use no-cache on HTML and immutable caching on hashed files
- Purge the CDN as part of every deploy
- Wrap lazy imports with a retry and a one-time reload
- Run a test of the key journeys right after every release
How FunnelGuard handles this
FunnelGuard detects this today. A robot visitor runs your real journeys on a schedule, such as a lead form or checkout, and watches the browser console. If a ChunkLoadError appears, it is flagged as a console error on that step. A failure is re-checked from a second region before one alert goes out, with a screenshot and a likely cause.
This helps you catch the problem soon after a deploy rather than from lost leads. FunnelGuard reports what it sees on the journey it runs. It cannot see errors that only affect a visitor on a particular network or browser it did not test. You can start with the Free plan (1 site, 2 journeys, daily checks, no card), or try a paid plan with a 3-day free trial.
Questions people ask
Why is my website showing ChunkLoadError: Loading chunk failed?
The browser could not download a JavaScript file that the page loads on demand. The most common reasons are a recent deploy that removed old files, a wrong asset path, or a cache or CDN serving a missing or wrong file. Open the Network tab to see the failing URL and its status code.
How do I fix ChunkLoadError after a deploy?
Keep the previous build's hashed files on the server for a few days, serve HTML with no-cache, and purge your CDN on each deploy. Also add a retry and a one-time page reload to lazy imports so open tabs recover on their own.
Why does ChunkLoadError only happen to some visitors?
It often affects people who opened the site before a deploy, or those served by a stale CDN or browser cache. Network blocks, ad blockers or flaky connections can also stop a chunk loading. That is why it can be missed in your own testing.
What is the difference between ChunkLoadError and Failed to fetch dynamically imported module?
They are the same kind of problem reported by different tools. ChunkLoadError comes from webpack, while Failed to fetch dynamically imported module is the browser message for native ES module imports used by Vite and others. Both mean a lazily loaded file could not be fetched.
Can ChunkLoadError lose me leads or sales?
Yes. If the failing chunk powers a form, cart or checkout, the visitor sees a blank or stuck page and cannot convert. Early page views still get counted, so traffic can look normal while conversions fall.
Should I just reload the page when a chunk fails to load?
Reloading once is a good fallback, because it fetches the new HTML that points to current chunks. Limit it to one reload per session so a file that is truly missing does not cause an endless loop. Show a clear message if it still fails.
How can I be alerted when ChunkLoadError happens on my site?
You need something that runs your key journeys regularly and watches the console. FunnelGuard does this with a robot visitor and flags a ChunkLoadError as a console error on the step, then sends one alert after re-checking from a second region.
Related issues
- PRF-122JS bundle 404 after deploy (stale cached HTML referencing old hashes)Fix guide
- PRF-117Console error on a funnel stepFix guide
- PRF-116Uncaught JavaScript exception on page loadFix guide
- PRF-133Page stuck on loading spinner foreverFix guide
- PRF-130Service worker serving stale or broken cached versionFix guide
- PRF-124CORS error blocking API call from the pageFix guide