I have been using a third-party react pdf viewer to render pdf files uploaded by the end-user in my volto site. Unfortunately, it was setup in a way in which it uses an external cdn. The code I used is below:
Is there a way to load the PDF files within the browser page in Volto without having to use an external CDN? I have been attempting to use the same plugin while using a local node_module package installed in the Volto addon itself yet I am not getting anywhere. It says that it was unable to read pdfjs-dist even though I had installed it locally as a dependency within the plugin.
I gave the suggested addon a try.
This is what I got in the console:
✔ Client
Compiled successfully in 520.73ms
✔ Server
Compiled successfully in 3.27s
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
/Users/rhennebrown/Plone525/frontend/Volto13151/node_modules/@bundled-es-modules/pdfjs-dist/build/pdf.js:27612
export default pdf_1;
^^^^^^
SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/rhennebrown/Plone525/frontend/Volto13151/node_modules/@mikecousins/react-pdf/dist/react-pdf.cjs.development.js:7:29)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
Yes, I ran yarn install and I am still getting the same error.
/Users/rhennebrown/Plone525/frontend/Volto13151/node_modules/@bundled-es-modules/pdfjs-dist/build/pdf.js:27612
export default pdf_1;
^^^^^^
SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/rhennebrown/Plone525/frontend/Volto13151/node_modules/@mikecousins/react-pdf/dist/react-pdf.cjs.development.js:7:29)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
Try to load volto-pdf-block as a development addon (clone it in src/addons, add it in jsconfig.json or use mrs-developer for that). It seems that there's a ESM file where a CJS file is expected... I don't know why. Which node version are you using?