React-pdf Missing class properties transform

1.8k Views Asked by At

I'm trying to display a pdf file on a web page with React.

The problem I have is that after installing react-pdf and importing import { DOCUMENT } from 'react-pdf' the project doesn't compile, showing the following error:

./node_modules/pdfjs-dist/build/pdf.js
SyntaxError: C:\Users\mavie\Escritorio\proyecto_ui\node_modules\pdfjs-dist\build\pdf.js: Missing class properties transform.
  3746 |   #isInEditMode = false;
  3747 |   #zIndex = AnnotationEditor._zIndex++;
> 3748 |   static _colorManager = new _tools.ColorManager();
       |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3749 |   static _zIndex = 1;
  3750 |
  3751 |   constructor(parameters) {

I've tried to reinstall the library, or look for the problem but I can't find something similar to this specifically.

1

There are 1 best solutions below

0
On

I recently ran into the same issue, and couldn't find any answers either. However, I managed to get it working by reverting react-pdf package down to 5.7.2 and that seemed to help

Also, I'm using the webpack 4 import instead:

import {Document, Page} from 'react-pdf/dist/esm/entry.webpack';