embroider-build / ember-auto-import

Zero config import from npm packages
Other
360 stars 109 forks source link

Strange import behavior with pdfjs v4 #614

Open dwickern opened 6 months ago

dwickern commented 6 months ago

Repro here: https://github.com/dwickern/ember-pdfjs-reproduction

In pdfjs v4 the project was converted to ESM. After upgrading pdfjs from v3 to v4, its default export is an unresolved promise:

Screenshot 2024-03-13 at 3 07 21 PM

To get it working, you actually have to await the imported module: https://github.com/dwickern/ember-pdfjs-reproduction/commit/f8aa137a5c9e858fa6dd293cfc00087c2f03dacc

Expected behavior: importing a module should resolve it

dwickern commented 6 months ago

There's a similar issue building with embroider, where the application route class is an unresolved promise:

Screenshot 2024-03-13 at 3 32 56 PM

Which manifests as an error:

Uncaught Error: Assertion Failed: Failed to create an instance of 'route:application'. Most likely an improperly defined class or an invalid module export.
    at assert (index.js:118:1)
    at InternalFactoryManager.create (index.js:372:1)
    at Proxy.create (index.js:204:1)
    at instantiateFactory (index.js:276:1)
    at lookup (index.js:223:1)
    at Container.lookup (index.js:121:1)
    at ApplicationInstance.lookup (container_proxy.js:19:1)
    at PrivateRouter.getRoute (router.js:183:1)
    at UnresolvedRouteInfoByParam.fetchRoute (router_js.js:714:1)
    at get route (router_js.js:648:1)

It seems that any module importing pdfjs will have its own exports broken. For example, in my app, a service imports pdfjs and all @service injections for that service are broken (they resolve to a Promise<Service> instead of the service).

Reproduction is on the embroider branch: https://github.com/dwickern/ember-pdfjs-reproduction/tree/embroider

ef4 commented 4 months ago

The commentary in https://github.com/embroider-build/embroider/issues/1948#issuecomment-2135678186 also applies here.

And the same workaround should apply. The only difference is that for ember-auto-import you must make sure you opted in to dynamic import support.