Need help using ember-auto-import dynamic import

I’m using dynamic import for perhaps the first time and finding myself in the deep end of the build pool.

We are generating PDF reports using jspdf, which involves loading a large static font and images - something like 30 Mb of compiled JS blobs we don’t want to burden ourselves with on startup. To avoid this (and also avoid incompatibilities with fastboot), we’re dynamically loading our library that imports jspdf and the blobs and coordinates their use when the user requests the report. We get:

WARNING in ./node_modules/jspdf/dist/jspdf.umd.min.js 195:141-151
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/@ebiz/aditools-design-report/lib/src/pdf.js
 @ C:/Users/rmack/AppData/Local/Temp/broccoli-12140X1sDlCgqiv9w/cache-576-bundler/staging/app.js
 @ multi C:/Users/rmack/AppData/Local/Temp/broccoli-12140X1sDlCgqiv9w/cache-576-bundler/staging/l.js C:/Users/rmack/AppData/Local/Temp/broccoli-12140X1sDlCgqiv9w/cache-576-bundler/staging/app.js

WARNING in ./node_modules/jspdf/dist/jspdf.umd.min.js 195:240-254
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/@ebiz/aditools-design-report/lib/src/pdf.js
 @ C:/Users/rmack/AppData/Local/Temp/broccoli-12140X1sDlCgqiv9w/cache-576-bundler/staging/app.js

and the chunk isn’t getting emitted. I think this has to do with its filters plugin which is computing AMD requires, but the things it requires are already pre-bundled in the minimized UMD module. What can I do to mitigate this?

It appears that the problem leading to the webpack warnings was fixed upstream, and delivered three days ago after existing for quite a while. Version bump seems to have resolved it. When I do a production build, I see the 30MB chunk getting generated.

However, when I do a local ember start, and it goes to load the chunk, it reports that it doesn’t exist, and indeed it isn’t showing in dist/. Any idea why a chunk would show up in a production build but not in a local one? How would I go about debugging this?

It turns out there is a known issue in ember-auto-import where if you import a library dynamically in your code but statically in a test, in any build that includes the tests, it doesn’t generate the chunk that the dynamic import needs. (This also explains the anomaly where the dynamic import was working yesterday but not today. Last night, the team member working on this piece added tests for it.) The issue and its workaround are listed in this issue.

So it appears I now have working code.

2 Likes