Pdf.js: Module not found: Error: Can't resolve 'worker-loader'

Created on 13 Aug 2020  路  3Comments  路  Source: mozilla/pdf.js

Attach (recommended) or Link to PDF file here: Not an issue while interacting with a pdf this is a webpack error when compiling

Configuration:

  • Web browser and its version: N/A
  • Operating system and its version: Happening on a Linux box
  • PDF.js version: Issue occurs on pdfjs-dist: 2.4.456 The fix I made was using the version I originally used at 2.2.228
  • Is a browser extension: No

Steps to reproduce the problem:

  1. The import looks like this on webpack version 4.41.2
    import PDFJS from 'pdfjs-dist/webpack';

What is the expected behavior? Application compiles correctly

What went wrong? error occurs during build "Module not found: Error: Can't resolve 'worker-loader'"

It's entirely possible this is not how the pdfjs-dist was supposed to be used I ended up using that over just pdfjs since I needed it to work on IE and chrome sets up the worker for me without the dist package

Most helpful comment

We found our issue. We were using worker-loader 3.0.1 which is a new major version. Switching to 2.0.0 resolved our problem.

All 3 comments

What went wrong? error occurs during build "Module not found: Error: Can't resolve 'worker-loader'"

Did you actually install the worker-loader package, since that needs to be done manually?

Does this example work, since it's not clear (to me at least) if you tried using it?


Finally, it's unlikely that anyone will be able to help without more context; hence please see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.

We're been experiencing the same issue after the latest update!

In our production build we get a o is not a constructor error on runtime.
We've tracked it down to pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker(); in /pdfjs-dist/webpack.js.
Currently importing pdfjs-dist classes such as getDocument crashes our app on runtime.

We've made sure worker-loader is installed.

Does anyone have a workaround?

We found our issue. We were using worker-loader 3.0.1 which is a new major version. Switching to 2.0.0 resolved our problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmisdm picture dmisdm  路  3Comments

azetutu picture azetutu  路  4Comments

aaronshaf picture aaronshaf  路  3Comments

brandonros picture brandonros  路  3Comments

kleins05 picture kleins05  路  3Comments