Open dwickern opened 1 month ago
pdf.js. is using top-level await. We can't make that work until we do https://github.com/emberjs/rfcs/pull/938.
A workaround until then is to access pdf.js via dynamic import only:
diff --git a/app/routes/application.js b/app/routes/application.js
index 1c602d9..9555db4 100644
--- a/app/routes/application.js
+++ b/app/routes/application.js
@@ -1,10 +1,10 @@
import Route from '@ember/routing/route';
-import { getDocument } from 'pdfjs-dist/webpack.mjs';
const url = '/fw4.pdf';
export default class ApplicationRoute extends Route {
async model() {
+ const { getDocument } = await import('pdfjs-dist/webpack.mjs');
const loadingTask = getDocument({ url });
return await loadingTask.promise;
}
This worked for me in your reproduction app.
PDF.js 4.3.136 just released and they no longer use top-level await, so it works now without the dynamic import.
Related issue https://github.com/mozilla/pdf.js/issues/17245 and fix https://github.com/mozilla/pdf.js/pull/18051
Reproduction here: https://github.com/dwickern/ember-pdfjs-reproduction/tree/embroider
The module which imports PDF.js will have its own exports broken. In the reproduction, the application route imports pdf.js. Its export resolves to a promise instead of the route class:
This results in an error:
If you import PDF.js in a service instead, all
@service
injections for that service will resolve to aPromise<Service>
instead of the service.There's a related problem with ember-auto-import https://github.com/embroider-build/ember-auto-import/issues/614