nextjs
build_error
ai_generated
partial
ChunkLoadError: Loading chunk X failed
ID: nextjs/loading-chunk-failed
82%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 14 | active | — | — | — |
Root Cause
Webpack chunk (code split piece) not found. Deploy replaced files while users had old HTML.
genericWorkarounds
-
90% success Add error boundary that triggers window.location.reload() on ChunkLoadError
class ErrorBoundary extends React.Component { componentDidCatch(e) { if (e.name === 'ChunkLoadError') window.location.reload(); } }Sources: https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary
-
85% success Use content-addressed filenames (default in Next.js) so old chunks remain available
default in Next.js
Sources: https://nextjs.org/docs/app/building-your-application/deploying
-
82% success Keep old build assets for a grace period during deployments
// In your deployment config, keep old _next/static assets: # nginx.conf: location /_next/static { alias /var/www/builds/current/_next/static; # Also serve previous build's assets: try_files $uri @previous_build; } # Or use a CDN with long cache TTLs for immutable assetsSources: https://nextjs.org/docs/app/building-your-application/deploying
Dead Ends
Common approaches that don't work:
-
Disable code splitting
80% fail
Destroys performance — one huge bundle
-
Force reload on every navigation
75% fail
Terrible UX — kills SPA behavior
Error Chain
Frequently confused with: