-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find module 'worker-loader!./build/pdf.worker.js' from 'webpack.js' #11925
Comments
@scottweitzner thanks for pointing me to the downstream issue. All I know is that pdfjs-dist uses webworkers and webworkers don't work well with Jest becuase Jest uses node from what I've read. I was hoping for a solution from the team. I've tried mocks and everything else I can think of. |
@mcoates1 No problem. It looks like the issue from my end was discussed and a fix was merged here. Looks like that change will resolve the downstream issue my team was having. I'd try pulling in the latest version once a patch release is made (most likely going to be v2.5.208). If that doesn't work then I'm afraid we might've had different issues with similar errors. Best of luck! |
I am facing same issue, any resolution yet? |
Hi @abhimanusharma . I found a workaround for this issue by keeping both
AND
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! |
For me, adding following to the Jest configuration also worked.
|
The |
I 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"
The text was updated successfully, but these errors were encountered: