Angular - Load Production chunk files failed after deploy
I managed the error of the route replacing its error handler and reloading if it found an error loading the chunk.
// Keep the original error handlerconst oldHandler = this.router.errorHandler;// Replace route error handlerthis.router.errorHandler = (err: any) => { // Check if there is an error loading the chunk if (err.originalStack && err.originalStack.indexOf('Error: Loading chunk') >= 0) { // Check if is the first time the error happend if (localStorage.getItem('lastChunkError') !== err.originalStack) { // Save the last error to avoid an infinite reload loop if the chunk really does not exists after reload localStorage.setItem('lastChunkError', err.originalStack); location.reload(true); } else { // The chunk really does not exists after reload console.error('We really don\'t find the chunk...'); } } // Run original handler oldHandler(err);};
I hope it helps you
I solved this issue moving my application to AWS and saving the files in S3!