embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
350 stars 149 forks source link

ChunkLoadError in headless automated tests #2459

Open lfloyd117 opened 2 weeks ago

lfloyd117 commented 2 weeks ago

We've recently started seeing a "ChunkLoadError" randomly in our tests:

stack: >
        ChunkLoadError
            at __webpack_require__.f.j (http://localhost:7357/assets/chunk.abc91d9cc4f415c2f459.js:1498:29)
            at http://localhost:7357/assets/chunk.abc91d9cc4f415c2f459.js:1352:40
            at Array.reduce (<anonymous>)

It happens randomly on various tests infrequently (but enough to cause issues), the only pattern able to observe is it always happens on acceptance tests on routes that are included in splitAtRoutes in our config. It's only started happening recently, trying to pin down a related change/timeline. Only recent changes I can think of was the following Embroider package updates:

@embroider/core 3.4.20 > 3.5.3
@embroider/compat 3.6.0 > 3.8.3

We parallelize our tests with ember-exam on 4 partitions. I have been unable to reproduce the issue locally at all (even in an environment matching our build servers) running either exam or in-browsers tests via a test server. We were on ember-exam v8.0.0 and I tried upgrading to v9.1.0 (latest currently) and there was no change in behavior. Our embroider package versions are below:

"@embroider/compat": "~3.8.3",
"@embroider/core": "~3.5.3",
"@embroider/router": "~2.1.8",
"@embroider/test-setup": "~4.0.0",
"@embroider/webpack": "~4.1.0",

It is worth it to note that we have seen reports of this error in production though there it may very well (and is often accepted by community members to be) a caching issue between releases. That said, we have been unable to reproduce the issues and these very well could be connected. Here is our current configuration:

const { Webpack } = require('@embroider/webpack'),
        embroiderApp = require('@embroider/compat').compatBuild(app, Webpack, {
            staticAddonTestSupportTrees: true,
            staticAddonTrees: true,
            staticInvokables: true,
            splitAtRoutes: [
                // a list of major feature main routes to split our code at. Example: 'videos', 'posts', etc
            ],
davidtaylorhq commented 2 weeks ago

It's not really a solution, but we were able to reduce the frequency of this issue by adding the webpack RetryChunkLoadPlugin.

lfloyd117 commented 1 week ago

@davidtaylorhq were you seeing this/did that help in automated tests?

davidtaylorhq commented 5 days ago

Yeah we were seeing the same error in QUnit tests, and adding the RetryChunkLoadPlugin seems to have reduced the frequency of the error