Utkarsh212 / react-pdftotext

A simple light weight react package to extract plain text from a pdf file.
https://www.npmjs.com/package/react-pdftotext
MIT License
9 stars 4 forks source link

Problem with Vercel deployment [ERR_REQUIRE_ESM] #9

Open valentindlr1 opened 2 weeks ago

valentindlr1 commented 2 weeks ago

I am able to use react-pdftotext locally without problem with Nextjs. But deploying it to Vercel is currently not possible. I tried many ways but I keep getting this error.

Error [ERR_REQUIRE_ESM]: require() of ES Module /vercel/path0/client/node_modules/react-pdftotext/node_modules/react-pdf/node_modules/pdfjs-dist/build/pdf.mjs not supported. Instead change the require of /vercel/path0/client/node_modules/react-pdftotext/node_modules/react-pdf/node_modules/pdfjs-dist/build/pdf.mjs to a dynamic import() which is available in all CommonJS modules. at mod.require (/vercel/path0/client/node_modules/next/dist/server/require-hook.js:65:28) at Object.<anonymous> (/vercel/path0/client/node_modules/react-pdftotext/node_modules/react-pdf/dist/cjs/index.js:30:28) { code: 'ERR_REQUIRE_ESM' }

I don't know what to do. Any help will be appreciated.

Edit: Worth to mention that I've been using react-pdftotext just fine the last few weeks.The problem showed up when I updated my Nextjs version to latest, and set Node version to 20.x in Vercel. I needed to do this in order to fix some problems with other libraries.

I will need to replace react-pdftotext for now, but I hope we can reach to a solution soon, since it's just the tool I need as simple as it is, and my code is already adapted to it.

spiderakm commented 1 week ago

You can fix this with dynamic import like this `import dynamic from 'next/dynamic';

const ReactPdfToText = dynamic(() => import('react-pdftotext'), { ssr: false }); `