react-pdf-viewer / starter

Some boilerplates to use React PDF viewer component
https://react-pdf-viewer.dev
25 stars 30 forks source link

Cannot read properties of null (reading 'useMemo') #49

Closed Heilemann closed 11 months ago

Heilemann commented 11 months ago

I'm getting this error in my CRA project:

ERROR
Cannot read properties of null (reading 'useMemo')
TypeError: Cannot read properties of null (reading 'useMemo')
    at Object.useMemo (http://localhost:3000/static/js/bundle.js:241387:25)
    at defaultLayoutPlugin (http://localhost:3000/main.f2519163e0f365851fb8.hot-update.js:1013:32)
    at PdfViewer (http://localhost:3000/main.991012cbdc34eb302c69.hot-update.js:29:124)
    at renderWithHooks (http://localhost:3000/static/js/bundle.js:144726:22)
    at mountIndeterminateComponent (http://localhost:3000/static/js/bundle.js:148012:17)
    at beginWork (http://localhost:3000/static/js/bundle.js:149308:20)
    at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:134318:18)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:134362:20)
    at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:134419:35)
    at beginWork$1 (http://localhost:3000/static/js/bundle.js:154293:11)

Here's the component:

import { Viewer, Worker } from '@react-pdf-viewer/core'
import { defaultLayoutPlugin } from '@react-pdf-viewer/default-layout'

import '@react-pdf-viewer/core/lib/styles/index.css'
import '@react-pdf-viewer/default-layout/lib/styles/index.css'

const PdfViewer = () => {
    const defaultLayoutPluginInstance = defaultLayoutPlugin()

    return (
        <Worker workerUrl='https://unpkg.com/pdfjs-dist@2.15.349/build/pdf.worker.js'>
            <div
                style={{
                    height: '750px',
                    width: '900px',
                    marginLeft: 'auto',
                    marginRight: 'auto',
                }}
            >
                <Viewer
                    fileUrl={`/assets/pdf/traveller.pdf`}
                    plugins={[defaultLayoutPluginInstance]}
                />
            </div>
        </Worker>
    )
}

export default PdfViewer

If I remove the plugin, that error goes away, but then I get one about useState instead.

Heilemann commented 11 months ago

Same issues as #47

Heilemann commented 11 months ago

Self goal. I had installed the libraries in the wrong folder (one up from my client, in my server).