Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: A dynamic import callback was invoked without --experimental-vm-modules in pdf2png #87

Open
brukri opened this issue Dec 16, 2024 · 1 comment

Comments

@brukri
Copy link

brukri commented Dec 16, 2024

The Error

I get the following runtime error in a CJS node.js (v22.12.0) micro service:

TypeError: A dynamic import callback was invoked without --experimental-vm-modules
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:264:11)
    at pdf2png (.../node_modules/.pnpm/pdf-visual-diff@0.14.0/node_modules/pdf-visual-diff/src/pdf2png/pdf2png.ts:74:27)
    at compareWithSnapshot (.../node_modules/.pnpm/pdf-visual-diff@0.14.0/node_modules/pdf-visual-diff/src/compare-pdf-to-snapshot.ts:223:31)
    at comparePdfToSnapshot (.../node_modules/.pnpm/pdf-visual-diff@0.14.0/node_modules/pdf-visual-diff/src/compare-pdf-to-snapshot.ts:150:12)
    at comparePdfs (.../node/document-generation-service/src/testutils/compare-pdfs.ts:14:26)
    at generate-registration-pdf.test.ts:56:7

It seems that the function pdf2png in pdf2png.ts does the following dynamic import:
const { getDocument } = await import('pdfjs-dist/legacy/build/pdf.mjs');

According to my understanding dynamic import aren't supported in CJS or how should I use the library in a CJS setup?

@moshensky
Copy link
Owner

There is a very basic example here: https://github.com/moshensky/pdf-visual-diff/tree/master/examples/cjs_sample. Nevertheless the only option might be adding --experimental-vm-modules argument when invoking Node.js.
Please note that an upstream dependency pdfjs-dist was updated not long ago to ESM so there aren't many options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants