Repository navigation
[Question]: How to make this work with Nextjs? #75
Replies: 4 comments
|
Thanks for the report! Next.js bundles the viewer files but not the PDF.js data folders ( This setup works in production ( "scripts": {
"postinstall": "node -e \"require('fs').cpSync('node_modules/@missing-elements/pdfjs-viewer/dist', 'public/pdfjs-viewer', { recursive: true })\""
}Run 'use client'
import { useEffect } from 'react'
export function PdfViewer({ src }) {
useEffect(() => {
import('@missing-elements/pdfjs-viewer')
}, [])
return <pdfjs-viewer-element src={src} assets-base="/pdfjs-viewer/" style={{ height: '100dvh' }} />
}With A CDN works too if you pin the exact package version, so the WASM matches the bundled PDF.js: Prefer |
|
I'm going to use the CDN path so I don't need to set this up manually. Our CI blocks postinstall scripts. What happens if I don't pin the CDN to a specific version? is it expected that it will break on any version change or is the wasm/js tolerant of version differences? |
|
No, it isn't tolerant. Pin the CDN to the exact version you have installed, and update both together. |
|
An update on the two Next.js problems I mentioned: #70 fixes the worker silently running on the main thread and the empty stylesheets with The data folders will still need a copy or a CDN. Loading them from the bundle automatically can't cover everything, because PDF.js loads the scripting sandbox, ICC profiles and annotation icons from folders, so I've dropped that idea (details in #66). Your pinned CDN UPD: The fixes are released https://github.com/missing-elements/pdfjs-viewer/releases/tag/v4.4.2 |
Uh oh!
There was an error while loading. Please reload this page.
Problem to solve
When using nextjs, most files work, but getting things like the
jbig2.wasmworking for some edge cases is a little tricky when using nextjs.Is there a recommended path for setting this up for nextjs?
Proposed solution
when using nextjs / vite or any bundler in react, somehow load them from the bundle automatically
Alternatives considered
using a CDN like
https://cdn.jsdelivr.net/npm/@missing-elements/pdfjs-viewer/dist/wasm/jbig2.wasmAdditional context
No response
All reactions