Uncaught (in promise): Error: Loading chunk 20 failed

Cool thx for the feedback and for commenting the issue in GitHub

I think you noted something really interesting down respectively “It only happens with the app being updated via the App Store.”

Not sure if it’s related but I recently reinstalled all the libs I use (see below), pushed some updates in store and since then I didn’t noticed the error in my Sentry console again…maybe I’m just lucky but maybe could that have helped? would you like guys/girls to give a try?

I mean:

 rm -r node_modules
 rm package-lock.json
 npm install

then build and ship new apps in store

I experiencing exact the same issue in web version of app (not ionic)
And also i keep all previous js/css assets for months

I’ve got about 5k events from more than 2k users in less that 20 days (3,5, 27 chunk)
So that is not a ionic fault

I’m agree with you I don’t think it’s sticky a Ionic error. I was more betting on webpack or maybe thought that it was a problem from the cordova-plugin-ionic-webview plugin…but since you face the problem too on the web :frowning:

have you see my previous post about deleting node_modules/package-lock.json, reinstalling, bundling and deploying. did you try this sometimes? did you notice less errors?

@glebmachine Can you share your package.json (+ cordova plugins)? This might point us to a common dependency which could cause the problem

Guess which error I just noticed in my console while running my pwa with ionic serve after a reload of the code?

GET http://localhost:8100/build/20.js 200 (OK)
Loading chunk 20 failed.

If I check the stacktrace from top I see

requireEnsure|@|bootstrap 75e906f…:108
webpackAsyncContext|@|src lazy:147

that particular last “src_lazy:147” lead to

function webpackAsyncContext(req) {
var ids = map[req];
if(!ids)
	return Promise.reject(new Error("Cannot find module '" + req + "'."));
    return __webpack_require__.e(ids[1]).then(function() {
	return __webpack_require__(ids[0]);
});
};

for me this confirm me that the problem is related to webpack, lazy loading and refreshing the bundles

like https://stackoverflow.com/a/48362939/5404186

P.S.: I close the issue I opened in ionic webview

is it solved in webpack v4.2.0? https://github.com/webpack/webpack/issues/5964

But if this applies for all ionic 3 users, then quite many should see/have this error. How can we solve it? Are there any workarounds?

My guess, I may be totally wrong, is that it’s a cache/reload/webpack problem. Therefore that would explain that it don’t always happens and that not everybody is screaming

About the solution, honestly I don’t know. If my guess is correct, it needs an update of webpack. There is a request of updating webpack in the ionic app-scripts project but it isn’t that successful so far https://github.com/ionic-team/ionic-app-scripts/issues/1403

So the best way to solve the problem for now is to restart the app when the error occur. What is the best way to restart the app programmatically?

Not sure that’s the solution actually. If the error occurs, is really the app not usable?

I also have this issue, started a few days ago. I have never seen this before.
ionic cordova run ios works fine as it downloads the file from the local web server.
ionic cordova emulate ios fails opening some .js files.
When I am tracking the error I can see that it tries to fetch the js file from: file:///build/28.js and it fails as the file is not there. Other files are fetched from file:///Users/me/Library/Developer/Coresimulator…/www/build/4.js

I do not understand this

OK, I am so lucky to get it with the Android emulator too. Files are loaded from file:///android_asset/… but some without this prefix, so those failed.
Good file path: file:///android_asset/www/build/main.js
Wrong file path: file:///build/28.js

No idea, it was ok yesterday :slight_smile:

We’re also getting this error on our web app with different chunks. I believe it’s linked to lazy-loading.

App becomes unusable for the parts that fail. Either the user is stuck with a blank screen and is required to constantly refresh until it works, or it loads the app but the pages which fail won’t load when a user clicks the button for it.

Not sure what’s the best way to fix this.

I really think that it has to do with the way bundle are generated. Upgrading webpack may solves the issue because the bundle won’t be called just something like “2.js” but with hash like “1389374298237abs32ad.js” and therefore the browser/webview/wkwebview will notice better if the code is new or not

UPDATE btw no more app-scripts in Ionic v4 (if I’m not mistaking), so if Angular CLI v6 use the last Webpack under the hood which may have solve the issue, it would be fix with Ionic v4 too

Strange, but setting locationStrategy back to ‘hash’ solved my problem. However I have a feeling that this is somehow related to @IonicPage option: priority: off.

I recently got a new laptop and when I tried to get my existing Ionic app up and running on it, it was throwing this same error. I tried all of the suggestions from here and StackOverflow to no avail. It turned out to be due to NodeJS. I had installed the latest version of NodeJS (10.6.0) instead of the recommended version. When it was downgraded to v8.11.3, it began working again. We were able to reproduce the issue on another machine as well.

+1, seeing this often via Sentry, always on iOS and at load time. Users are complaining about random issues with the app being unstable.

@bvamos, any further confirmation this resolved the issue for you?

We also see similar error, also in Sentry.

My observation is that in parallel to this error we see sometimes errors like “XHR error loading assets/lang/en.json”. Sometimes both “failed chunk” and this error in the same user session. Which gives me idea that maybe something is wrong with XHR? With polyfills.js that patches XHR? With cordova-plugin-webview that adds a proxying http server?..

Error is really annoying…

I have the exact same problem: lazy loading, iOS only, on boot time.

@bvamos can you please provide more details on how did you change locationStrategy to ‘hash’?