I’m trying to use pdf.js and importing it like so:
import PDFJS from "../vendor/pdf.mjs"
so I can use it in a Hook to render the 1st page of a PDF, but I’m getting:
✘ [ERROR] Top-level await is not available in the configured target environment ("es2018")
vendor/pdf.mjs:16837:53:
16837 │ ...ck_exports__ = globalThis.pdfjsLib = await __webpack_exports__;
╵ ~~~~~
I’ve tried incrementing the es version in config.exs to no avail.
✘ [ERROR] Top-level await is currently not supported with the "iife" output format
vendor/pdf.mjs:16837:53:
16837 │ ...ck_exports__ = globalThis.pdfjsLib = await __webpack_exports__;
╵ ~~~~~
import pdfJS from 'pdfjs-dist';
import 'pdfjs-dist/build/pdf.worker';
....
[watch] build started (change: "js/pdf_preview/index.js")
✘ [ERROR] Could not resolve "pdfjs-dist/build/pdf.worker"
js/pdf_preview/index.js:3:7:
3 │ import 'pdfjs-dist/build/pdf.worker';
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "pdfjs-dist/build/pdf.worker" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Top-level await is not available in the configured target environment ("es2017")
node_modules/pdfjs-dist/build/pdf.mjs:16837:53:
16837 │ ...ck_exports__ = globalThis.pdfjsLib = await __webpack_exports__;
[watch] build started (change: "js/pdf_preview/index.js")
✘ [ERROR] Top-level await is currently not supported with the "iife" output format
node_modules/pdfjs-dist/build/pdf.mjs:16837:53:
16837 │ ...ck_exports__ = globalThis.pdfjsLib = await __webpack_exports__;
Hey @ghenry ,
Me and my colleagues are having the same issue. If I read that github issue correctly they solve that by using vite.
Do you (or anybody else) have a working example with phoenix? Or did you just simply used a different release?