Skip to content

Known issues

Wojciech Maj edited this page Nov 2, 2018 · 10 revisions

Compatibility with react-file-viewer

Installing react-file-viewer along React-PDF may result in errors and/or inability to use either.

SyntaxError: expected expression, got '<'

By default React-PDF is looking for its worker under /pdf.worker.js. Some applications instead of throwing 404s, return a HTML page for React app to handle the situation. pdf.worker.js is expected to be a JavaScript file and is evaluated as such, so this situation results in an error.

If you use default entry for React-PDF, ensure you're copying pdf.worker.js to your dist directory as instructed in README.

Create React App

It's best to eject your app and use e.g. CopyWebpackPlugin to copy pdf.worker.js during build.

If you don't want to eject right now, change the configuration to load the worker from an external CDN:

import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

ReferenceError: window is not defined

This is an issue that's likely to happen if you use Webpack 4 or Create-React-App 2 which uses Webpack 4 internally. It's a known issue in worker-loader.

  • If you have access to Webpack configuration, see the issue linked above for a workaround.

Create React App

Use default entry (react-pdf and not react-pdf/dist/entry.webpack).

It's best to eject your app and use e.g. CopyWebpackPlugin to copy pdf.worker.js during build.

If you don't want to eject right now, change the configuration to load the worker from an external CDN:

import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

pdf.js-dependent

React-PDF is highly dependent on a super awesome library pdf.js by Mozilla. However, pdf.js is not supporting PDFs in its full glory, so several things might not work.

  • You might get a warning message Warning: Knockout groups not supported. every time the page is rendered. See pdf.js #3136.
  • You might get a warning message Warning: TT: undefined function: 23 or similar when using SVG rendering mode.
  • You might get a warning message The provided value 'moz-chunked-arraybuffer' is not a valid enum value of interface XMLHttpRequestResponseType. on Google Chrome. See pdf.js #6306.