How to migrate from pdfjs-dist 3.11.174 to version 4 on a node.js project #17989
Replies: 7 comments 2 replies
-
Thanks for moving to correct position |
Beta Was this translation helpful? Give feedback.
-
Can nobody help? |
Beta Was this translation helpful? Give feedback.
-
You need to set |
Beta Was this translation helpful? Give feedback.
-
I also want to ask, do I have to use the old version if I want to use it in CommonJs |
Beta Was this translation helpful? Give feedback.
-
If not possible, I would like to know the latest version that supports commonjs |
Beta Was this translation helpful? Give feedback.
-
I have the same error when trying to upgrade pdfjs. But my porject is a bit different. I'm using So I tried to use a dynamic async And that is not surprising since this I think pdfjs is the only package we use that does not export a commonjs build, and I can't find a way to make it work properly. Any idea? |
Beta Was this translation helpful? Give feedback.
-
Thanks to a friend with knowledge in javascript jungle, I have finally a working version. My project is a streamlit application but you can find the useful information in the repository, https://github.com/lfoppiano/streamlit-pdf-viewer/tree/enable-text-content-2 in particular the important changes: lfoppiano/streamlit-pdf-viewer@5f09846 |
Beta Was this translation helpful? Give feedback.
-
I hope someone can help me with this issue.
I am using pdfjs-dist version 3.11.174 without any problems in my node.js 20.11.0 typescript project ("target": "esnext", "module": "commonjs", "moduleResolution": "node",)
Now I wanted to upgrade to version 4. But there are only mjs file now.
The problem is that even the documentation for node.js uses
But when I try to do it this way I get an error from typescript:
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/pdfjs-dist/build/pdf.mjs not supported.
Instead change the require of .../node_modules/pdfjs-dist/build/pdf.mjs to a dynamic import() which is available in all CommonJS modules.
So then I tried that:
import('pdfjs-dist/legacy/build/pdf.mjs').then(pdfjsLib => {
const { getDocument } = pdfjsLib;
// use getDocument here
}).catch(error => {
console.error('Error loading the module', error);
});
But even then I get nearly the same error message. What do I need to change? Is there somewhere a migration document that explains how to migrate from 3 to 4 for a node.js project?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions