After I split my single-page application bundle into multiple chunks with dynamic import and React lazy loading, I began to occasionally see errors in production. Something was causing a runtime error that would cause the entire app to crash and bubble up to my React error boundary. Looking through the logs, the offending error was this:

Error: ChunkLoadError: Loading chunk 0 failed.

Root Cause

After some digging, I realized the root cause was the network. More chunks meant more requests, which meant more chances of a network failure. If any one of the requested chunks failed, the above error would be triggered. But I couldn’t really do anything to fix a user’s network. So, what’s the next best thing?

#javascript

How to Deal with Network Failures from Code Splitting
1.30 GEEK