I'm just trying a simple example to download a PDF with a PDFDownloadLink and its throwing the above error when the component renders.
const ReportPDF = () => (
<Document>
<Page size="A4">
<View>
<Text>Section #1</Text>
</View>
<View>
<Text>Section #2</Text>
</View>
</Page>
</Document>
);
...
render (
<div>
<PDFDownloadLink document={<ReportPDF/>} fileName="somename.pdf">
{({loading}) => loading ? <Button>Loading</Button> : <Button>PDF</Button>}
</PDFDownloadLink>
</div>
)
Can you provide a bit more of the error thread?
Thanks for this library @diegomura. I am running into the same issue seemingly when my pdf gets to a certain size, ~around 50 pages. Here is the error below.

It does not seem to be an issue with the code because if i run each section separately it works, but when i run the whole pdf together I get the error above. Also I am running the PDF server side with node.
Please let me know if you need any additional info. Thanks for your help!
I'm seeing this too.
Note, I'm seeing it in Chrome, but not Safari.
I am using a custom typeface as well as the PDFViewer frame, if that helps.
3cc0.08eca5fef36a4663495d.js:1 TypeError: _nbind.externalList[e].dereference is not a function
at __nbind_free_external (3cc0.08eca5fef36a4663495d.js:26)
at $i (3cc0.08eca5fef36a4663495d.js:26)
at Xi (3cc0.08eca5fef36a4663495d.js:26)
at No (3cc0.08eca5fef36a4663495d.js:26)
at Mm (3cc0.08eca5fef36a4663495d.js:26)
at Om (3cc0.08eca5fef36a4663495d.js:26)
at gx (3cc0.08eca5fef36a4663495d.js:26)
at n.unsetMeasureFunc (3cc0.08eca5fef36a4663495d.js:26)
at t.cleanup (3cc0.08eca5fef36a4663495d.js:1)
at 3cc0.08eca5fef36a4663495d.js:1
(anonymous) @ 3cc0.08eca5fef36a4663495d.js:1
3cc0.08eca5fef36a4663495d.js:26 Uncaught (in promise) TypeError: _nbind.externalList[e].dereference is not a function
at __nbind_free_external (3cc0.08eca5fef36a4663495d.js:26)
at $i (3cc0.08eca5fef36a4663495d.js:26)
at Xi (3cc0.08eca5fef36a4663495d.js:26)
at No (3cc0.08eca5fef36a4663495d.js:26)
at Mm (3cc0.08eca5fef36a4663495d.js:26)
at Om (3cc0.08eca5fef36a4663495d.js:26)
at gx (3cc0.08eca5fef36a4663495d.js:26)
at n.unsetMeasureFunc (3cc0.08eca5fef36a4663495d.js:26)
at t.cleanup (3cc0.08eca5fef36a4663495d.js:1)
at 3cc0.08eca5fef36a4663495d.js:1
3cc0.08eca5fef36a4663495d.js:42 Uncaught Error: stream.push() after EOF
at w (3cc0.08eca5fef36a4663495d.js:33)
at n.Vks2.b.push (3cc0.08eca5fef36a4663495d.js:33)
at n.value (3cc0.08eca5fef36a4663495d.js:33)
at n.value (3cc0.08eca5fef36a4663495d.js:33)
at b.s.emit (3cc0.08eca5fef36a4663495d.js:42)
at F (3cc0.08eca5fef36a4663495d.js:33)
at 3cc0.08eca5fef36a4663495d.js:33
at p.F63i.p.run (commons.10ec448a93aa7301ef7a.js:1030)
at d (commons.10ec448a93aa7301ef7a.js:1030)
3cc0.08eca5fef36a4663495d.js:42 Uncaught Error: stream.push() after EOF
at w (3cc0.08eca5fef36a4663495d.js:33)
at n.Vks2.b.push (3cc0.08eca5fef36a4663495d.js:33)
at n.value (3cc0.08eca5fef36a4663495d.js:33)
at n.value (3cc0.08eca5fef36a4663495d.js:33)
at b.s.emit (3cc0.08eca5fef36a4663495d.js:42)
at F (3cc0.08eca5fef36a4663495d.js:33)
at 3cc0.08eca5fef36a4663495d.js:33
at p.F63i.p.run (commons.10ec448a93aa7301ef7a.js:1030)
at d (commons.10ec448a93aa7301ef7a.js:1030)
I am also getting this behavior, but not with big files. When I try to render a single/two page PDF with just a bunch of tables for a couple of times, my Chrome tab freezes and I get the same message @paintedbicycle pasted right above
Same here, unfortunately :(
In my case, it's happening when using @react-pdf/styled-components, and applying the following styles to the View component:
EDIT: Seems to be random, actually. Originally I thought it was because of the styled components, but I can't really tell for sure now.
export const Filled = styled.View`
**flex-direction: 'row';**
**align-items: 'stretch';**
background-color: ${props => props.backgroundColor || props.theme.primaryColor};
color: ${props => props.color || '#FFF'};
padding: 5px 10px;
`;
Only the properties surrounded by ** is causing this. The others work perfectly.
Perhaps this might help:
index.js:2178 TypeError: Cannot read property 'dereference' of undefined
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
__stack_frame_overlay_proxy_console__ @ index.js:2178
index.js:2178 TypeError: _nbind.externalList[num].dereference is not a function
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at View.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
__stack_frame_overlay_proxy_console__ @ index.js:2178
index.js:2178 TypeError: Cannot read property 'dereference' of undefined
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
__stack_frame_overlay_proxy_console__ @ index.js:2178
index.js:2178 TypeError: _nbind.externalList[num].dereference is not a function
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
__stack_frame_overlay_proxy_console__ @ index.js:2178
3summary:1 Uncaught (in promise) TypeError: Cannot read property 'dereference' of undefined
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
summary:1 Uncaught (in promise) TypeError: _nbind.externalList[num].dereference is not a function
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at View.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
summary:1 Uncaught (in promise) TypeError: Cannot read property 'dereference' of undefined
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
summary:1 Uncaught (in promise) TypeError: _nbind.externalList[num].dereference is not a function
at __nbind_free_external (nbind.js:597)
at wf (nbind.js:3299)
at vf (nbind.js:3297)
at hh (nbind.js:3517)
at bq (nbind.js:5837)
at $p (nbind.js:5833)
at OC (nbind.js:9653)
at Bound.unsetMeasureFunc (nbind.js:1473)
at Text.cleanup (react-pdf.browser.es.js:309)
at react-pdf.browser.es.js:307
at Array.forEach (<anonymous>)
at Page.cleanup (react-pdf.browser.es.js:306)
at react-pdf.browser.es.js:5011
at Array.forEach (<anonymous>)
at Document.cleanup (react-pdf.browser.es.js:5010)
at Root.cleanup (react-pdf.browser.es.js:90)
at Root._callee$ (react-pdf.browser.es.js:114)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:271)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
events.js:59 Uncaught Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:271)
at PDFDocument.webpackJsonp../node_modules/readable-stream/lib/_stream_readable.js.Readable.push (_stream_readable.js:245)
at PDFDocument._write (pdfkit.browser.es.js:3731)
at PDFReference.finalize (pdfkit.browser.es.js:255)
at Deflate.webpackJsonp../node_modules/events/events.js.EventEmitter.emit (events.js:96)
at endReadableNT (_stream_readable.js:1010)
at afterTickTwo (index.js:27)
at Item../node_modules/process/browser.js.Item.run (browser.js:153)
at drainQueue (browser.js:123)
events.js:59 Uncaught Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:271)
at PDFDocument.webpackJsonp../node_modules/readable-stream/lib/_stream_readable.js.Readable.push (_stream_readable.js:245)
at PDFDocument._write (pdfkit.browser.es.js:3731)
at PDFReference.finalize (pdfkit.browser.es.js:255)
at Deflate.webpackJsonp../node_modules/events/events.js.EventEmitter.emit (events.js:96)
at endReadableNT (_stream_readable.js:1010)
at afterTickTwo (index.js:27)
at Item../node_modules/process/browser.js.Item.run (browser.js:153)
at drainQueue (browser.js:123)
at cleanUpNextTick (browser.js:106)
3sentry.io/api/1341698/store/?sentry_key=e0e474a0fab14f919147bc25cd32429a&sentry_version=7:1 Failed to load resource: the server responded with a status of 403 (FORBIDDEN)
10events.js:59 Uncaught Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:271)
at PDFDocument.webpackJsonp../node_modules/readable-stream/lib/_stream_readable.js.Readable.push (_stream_readable.js:245)
at PDFDocument._write (pdfkit.browser.es.js:3731)
at PDFReference.finalize (pdfkit.browser.es.js:255)
at Deflate.webpackJsonp../node_modules/events/events.js.EventEmitter.emit (events.js:96)
at endReadableNT (_stream_readable.js:1010)
at afterTickTwo (index.js:27)
at Item../node_modules/process/browser.js.Item.run (browser.js:153)
at drainQueue (browser.js:123)
at cleanUpNextTick (browser.js:106)
Hi there,
I've also faced this issue. Crashed my Chrome as well.
I presume it affects when there is a backend setState() going on and it initiates another "render()" that cause it to happen, though I am unsure what the error of "TypeError: Cannot read property 'dereference' of undefined" is all about.
Tentatively, my only work around is to take out the entire render code that used
Hopefully, somehow this is get resolved, as I did spent a lot of time just to pre-code the live-render of a one-page PDF.
@diegomura Getting the same "Cannot read property 'dereference' of undefined" error when i update the state of a component that includes the react-pdf form--which gets rerendered with the new state. Is this being worked on? The ticket has been open/unresolved for a while now...
I believe this might be related to #420.
@diegomura i'm getting the same error when i use Image component from @react-pdf/renderer
I've been playing with react-pdf or around two weeks now and I mostly get these type of errors if rendering is interrupted.
Try preloading everything before trying to render with react-pdf. It seems that re-renders are a common cause for problems.
That includes fonts, images (urls are fine though), async data. Fetch it all in your container and THEN render the PDF for the best results.
I had the same error when I passed a data not with props, but with the mst store and after saving the pdf this error appeared at the moment when I reset the store.
_nbind.externalList[e].dereference is not a function
In my case, I was having the same issue and I tried with shouldComponentUpdate function returning false, that worked for me.
I got the same error
<PDFViewer width="100%" style={{ height: '90vh' }}>
<MyDocument
{ ...this.state.propsToPdf }/>
</PDFViewer>
Cause I updated propsToPdf on the fly
Now I'm setting loading and render only after props propagate and it works!!!
{
!this.state.loading &&
<PDFViewer width="100%" style={{ height: '90vh' }}>
<MyDocument
{ ...this.state.propsToPdf }/>
</PDFViewer>
}
I have a form where users input data and then click a Download link to have a PDF version of the form. Basically the structure of my code was: <PDFDownloadLink component={<PDFResume name={this.state.name}>}> (I'm simplifying here)
I was quite surprised to learn that the PDFResume component was re-rendered _every time_ a user type one letter in the form. This happened because typing a letter in the form changed this.state.name, of course.
But I would expect the PDF to be rendered only when the user clicks the PDFDownloadLink button. It would be more efficient in terms of CPU time and there would be no multiple renders that seem to be the cause of the current bug.
Until a permanent fix is released for the current bug, or (even better) until PDFDownloadLink is modified to render only when clicked, I implemented that workaround: https://github.com/diegomura/react-pdf/issues/420#issuecomment-517367494. If not using Gatsby, replace document.getElementById('___gatsby') by document.getElementById('root').
Hello,
I got the sem error in PDF
Please help me

I got same error when I added wrap={false} to Page component, but it works when I use this prop for View, Text components. I am using next.js. @diegomura help plz
In my case, I was having the same issue and I tried with shouldComponentUpdate function returning false, that worked for me.
Thanks. It worked for my
Hey people, try to read through this bug report: https://github.com/diegomura/react-pdf/issues/420. This helped me.
Long story short, if you're generating PDF just for download, do it conditionally. Hope this helps someone.
I can confirm this is caused by the rerendering of a BlobProvider and, as @sebastijandumancic and many other said, you need to only render the provider when you have everything prepared, and don't rerender it.
The solution that worked for me is something like this:
BlobProvider before document node is readyBlobProvider unless your document changesBlobProvider if you have a new document nodeit would look like this:
// use React.memo for 2.
const BlobProviderWrapper = React.memo(({ document }) => {
if(!document) return null; // to satisfy 1.
// key={Math.random()} to satisfy 3.
return <BlobProvider key={Math.random()} document={document}>
...
</BlobProvider>
});
and, although key={Math.random()} would be bad for performance, we're safe since this is handled inside the React.memo AND we have the if null before
Apparently you should render it only once, so just use "useMemo":
const DownloadPdf = () => {
return useMemo(
() => (
<PDFDownloadLink document={<MyDocument />} fileName="some-nane.pdf">
{({ loading }) => (loading ? 'loading...' : 'download')}
</PDFDownloadLink>
),
[],
)
}
Just in case this helps anyone
I was running into this issue because I wanted to have both a preview and styled download link, using PDFDownloadLink and PDFViewer as siblings resulted in them both trying to render the same PDF separately at the same time giving this error, so I tried using BlobProvider to generate the PDF once and pass it to both the link and preview, the problem there was that the PDFViewer only accepts a Document as children, meaning to use it you'll be generating a new PDF which also caused this error and really exacerbated issue #544. I found a somewhat decent work-around using react-pdfobject (which nicely accepts the data URL from a @react-pdf/renderer blob) in a pattern like this to ensure the document render only gets called once on mount, then passing the same data to both the download link and preview:
import React, { useState, useEffect } from 'react'
import { PDFObject } from 'react-pdfobject'
import { pdf } from '@react-pdf/renderer'
import Document from './Document'
export const PdfView = () => {
const [pdfData, setPdfData] = useState<{
loaded: boolean
url?: string
blob?: Blob
}>({ loaded: false })
useEffect(() => {
;(async () => {
const blob = await pdf(<Document />).toBlob()
const url = URL.createObjectURL(blob)
setPdfData({
loaded: true,
url,
blob,
})
})()
}, [])
return !pdfData.loaded ? (
<LoadingStatus />
) : (
<div>
<a href={pdfData.url!} download="filename.pdf" type="application/pdf">
<Button endIcon={<DownloadIcon />}>Download</Button>
</a>
<PDFObject
url={pdfData.url!}
fallbackLink={false}
containerProps={{
style: { height: 600 },
}}
/>
</div>
)
}
It still locks up on large documents due to the fact PDF generation happens in the main thread as per #544 / #464, but at least now it's not generating each document twice (once for link and once for preview), doesn't throw a bunch of errors/give blank PDFs, and can display some loading message while the user waits.
Most helpful comment
Apparently you should render it only once, so just use "useMemo":