L
L
LolaHuligang2021-04-05 13:35:38
JavaScript
LolaHuligang, 2021-04-05 13:35:38

React (create-react-app) why is there a compilation error?

Good afternoon,
I can not figure out the error.
Added a third-party react-pdf module to the application that uses pdf.js.
After some time, when running npm start, an error began to appear in pdf.worker.js:

Line 815:18:  Unexpected use of 'self'  no-restricted-globals
  Line 816:25:  Unexpected use of 'self'  no-restricted-globals
  Line 818:51:  Unexpected use of 'self'  no-restricted-globals

It is interesting that the error occurs during the first compilation, and after any minor editing (remove / put a comment), when recompiling everything works as it should, but because of this I can not build build.
When trying to remove eslint in pdf.worker.js: Build
/*eslint-disable*/
with an error, but now adding /*eslint-disable*/ to pdf.worker.js stopped working for some reason.
Unfortunately, I'm not familiar with pdf.js, but I came across a post that said that there might be compilation problems due to the api. But, if so, how to solve the problem, I do not know.
React-pdf is attached to the module in the standard way:
import {Document, Page, pdfjs} from 'react-pdf';
import pdfjsWorker from '../../build/pdf.worker.entry';
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

Everything works without problems when recompiling on npm start, but because of these errors I can’t put it on prod.
I currently have prettier on VS Code, maybe this is related to it?
Help, please, what other assumptions can there be, why the assembly does not work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LolaHuligang, 2021-04-07
@LolaHuligang

The solution may be useful to someone:
import {Document, Outline, Page, pdfjs} from 'react-pdf';
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry';
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question