Cannot find module 'worker-loader!./build/pdf.worker.js' from 'webpack.js'
See original GitHub issueI am running "react": "^16.13.1"
which was created using create-react-app. I am trying to run Jest tests and I keep getting the following error:
Cannot find module 'worker-loader!./build/pdf.worker.js' from 'webpack.js'
My import statement in my component looks like this:
import { PDFJS } from 'pdfjs-dist/webpack'
However, when I remove webpack from the import, the error goes away and things “seem” to work just fine.
import { PDFJS } from 'pdfjs-dist'
Can someone explain to me the difference between having webpack in the import statement vs not having it? Do I even need it? I’ve been trying to research this issue for days and have hit a wall so any input would be very helpful.
FYI, this is the version of pdfjs-dist that is in my package.json
"pdfjs-dist": "^2.3.200"
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:7
Top GitHub Comments
For me, adding following to the Jest configuration also worked.
Hi @abhimanusharma . I found a workaround for this issue by keeping both
import { PDFJS } from 'pdfjs-dist/webpack'
AND
import { PDFJS } from 'pdfjs-dist'
The top works in the normal execution of the code while the bottom works with Jest. Seems like jest doesn’t work well with web workers. The solution was to create an environment variable called “TESTING” or something like that and toggle between the two imports if the env variable exists or not.
Hope this helps!