Error message
ChunkLoadError: Loading chunk failed
A user opened your app before a deploy, then clicked something that loads code on demand. The browser asks for a file from the old build, the server no longer has it, and the import fails. The fix has two parts: keep the old files a while, and recover in the page when it happens anyway.
Examples run on 19 November 2026 with Chromium 156, webpack 5.112.2, Next.js 16.4.6 (Turbopack), Vite 8.3.8 and the Sentry browser SDK 11.12.0. Errilo is in private beta.
What the message says
Bundlers split an app into chunks: files downloaded by import() only when they are needed. Their names contain a hash of their content (764.fb4f875c.js), so every build has its own names. When a chunk can’t be loaded, the promise returned by import() is rejected. The wording depends on the bundler:
| Bundler | Error |
|---|---|
| webpack 5.112.2 | ChunkLoadError: Loading chunk 764 failed., then on a second line (error: <chunk URL>) |
| Next.js 16.4.6, Turbopack build (the default) | ChunkLoadError: Failed to load chunk /_next/static/chunks/0bbom-qvnune7.js from module 67822 |
Vite 8.3.8 (native import()) | TypeError: Failed to fetch dynamically imported module: <chunk URL> |
With webpack, the error also has a type property (error when the request failed, as on a 404) and a request property, the chunk’s URL. It is a rejected promise, not a thrown exception: unless your code catches it, it ends up in the unhandledrejection event.
Cause: the tab is older than the deploy
- The page was loaded from build N. Its main script knows the names of build N’s chunks.
- You deploy build N+1. The server now serves only the files of build N+1.
- The tab, still open, asks for a chunk of build N: 404, and the import fails.
The error only hits users who had the app open across a deploy, and only on the first action that needs a chunk they haven’t downloaded yet. Anything else that stops the file from loading raises the same error; this page covers the deploy case.
A variant: a server that answers every unknown URL with index.html (the fallback of a single-page app) returns HTML with a 200 status instead of a 404. In our test the browser then raised two errors for one cause: SyntaxError: Unexpected token '<', then webpack’s Loading chunk 764 failed. with (missing: <chunk URL>) and type set to missing. Answer a 404 for missing static files.
Minimal reproduction
A webpack app whose chart is loaded on click:
// src/index.js: the chart code is only downloaded on click
document.querySelector('#open-chart').addEventListener('click', async () => {
const { renderChart } = await import('./chart.js');
renderChart(document.querySelector('#chart'));
});Name the files after their content and empty the output folder at each build, as a deploy does:
output: {
filename: '[name].[contenthash:8].js',
chunkFilename: '[name].[contenthash:8].js',
clean: true,
},- Build, serve the output folder, open the page.
- Change
chart.jsand build again:764.fb4f875c.jsis deleted and replaced by a file with another name. - Click the button in the tab you opened first:
ChunkLoadError: Loading chunk 764 failed.
Fixes, from the simplest to the most robust
Reload the page once. The reloaded page gets the new build, and the click works. The guard in sessionStorage prevents a reload loop if the chunk is really gone: in our test, a second failure within the minute did not reload the page again.
// After a deploy, an old tab asks for chunks that no longer exist: reload once to get the new build.
window.addEventListener('unhandledrejection', (event) => {
if (event.reason?.name !== 'ChunkLoadError') return;
// At most one reload per minute, so a chunk that is really missing can't cause a reload loop.
const last = Number(sessionStorage.getItem('chunk-reload-at') ?? 0);
if (Date.now() - last < 60_000) return;
sessionStorage.setItem('chunk-reload-at', String(Date.now()));
window.location.reload();
});This handler works with webpack (the error is named ChunkLoadError) and with Next.js 16, Turbopack included. In Next.js, put it in instrumentation-client.ts, next to Sentry.init() (see the Next.js guide): we checked that after a redeploy, the old tab reloads and the second click shows the new build’s content. The reload loses what the page held in memory, a half-filled form for instance.
With Vite, the error is a TypeError, but Vite fires a vite:preloadError event on window first. Same guard:
window.addEventListener('vite:preloadError', () => {
const last = Number(sessionStorage.getItem('chunk-reload-at') ?? 0);
if (Date.now() - last < 60_000) return;
sessionStorage.setItem('chunk-reload-at', String(Date.now()));
window.location.reload();
});Don’t call event.preventDefault() in this handler. Vite then resolves the import with undefined, and your code fails before the reload with another error: TypeError: Cannot destructure property 'renderChart' of '(intermediate value)' as it is undefined.
Keep the old files online after a deploy. Since every file is named after its content, the files of two builds never collide: publish the new build next to the old one instead of replacing it, and remove old files only after a few days. An old tab then finds its chunks, and the error doesn’t happen at all. The reload above stays useful for tabs that are older still.
How Errilo shows it
The Sentry browser SDK reports the rejection as an unhandled error. Errilo groups occurrences on the exception type and the frames of the stack trace (file and function), not on the message: in our test, chunks 764 and 72 of the same build landed in the same issue, although the chunk number and URL differ in the message.
The file names, though, change with every build: the frames of build N point to main.778121b1.js, those of build N+1 to main.52165203.js, and without source maps each deploy opens a new ChunkLoadError issue. To get a single issue for every build and every chunk, give these errors the same fingerprint in beforeSend. Errilo uses the fingerprint sent by the SDK:
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
beforeSend(event, hint) {
// Every stale chunk in one issue, whatever the build and the chunk.
const error = hint.originalException;
if (error instanceof Error && error.name === 'ChunkLoadError') {
event.fingerprint = ['chunk-load-error'];
}
return event;
},
});Each occurrence carries the release of the build the tab had loaded, not the new one: in our test, the errors raised after the deploy of N+1 came with release N. The issue’s releases show which deploy left tabs behind.
Errilo has no inbound filters on the server: if you would rather not receive these errors at all, drop them in the SDK (ignoreErrors, beforeSend). We’d keep them, grouped: a peak right after a deploy shows that old files disappear too early.