Skip to content

Known issues

Wojciech Maj edited this page Oct 5, 2018 · 10 revisions
  • Installing react-file-viewer along React-PDF may result in errors and/or inability to use either.

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.

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.
  • If you don't have such possibility, for example if you're using Create-React-App and you have not ejected yet, change the configuration to load the worker from an external CDN:
    import { pdfjs, Document, Page } from 'react-pdf';
    pdfjs.GlobalWorkerOptions.workerSrc = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.550/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.
  • If you don't have such possibility, for example if you're using Create-React-App and you have not ejected yet, use default entry (react-pdf and not react-pdf/dist/entry.webpack) and change the configuration to load the worker from an external CDN:
    import { pdfjs, Document, Page } from 'react-pdf';
    pdfjs.GlobalWorkerOptions.workerSrc = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.550/pdf.worker.js';