question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack entry point cannot find worker-loader in Yarn 2 repo

See original GitHub issue

Attach (recommended) or Link to PDF file here: https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf

Configuration:

  • Web browser and its version: Firefox 84.0
  • Operating system and its version: Ubuntu 20.10
  • PDF.js version: 2.6.347
  • Also note: Webpack 5.11.0 and Yarn 2.3.3 workspaces

Steps to reproduce the problem: To see the manual worker setup resort to fake worker:

  1. clone and setup with Yarn 2: https://github.com/jcamden/pdfjs-yarn-2
  2. run the webpack dev server with yarn start
  3. check browser console log for ‘Warning: Setting up fake worker.’

To see the webpack entry point fail:

  1. uncomment line 8 of packages/client/App.tsx “// pdfWebpackEntry(‘./dummy.pdf’);”
  2. run the webpack dev server with ‘yarn start’
  3. check terminal for ‘Module not found: Error: Can’t resolve ‘worker-loader’…’

What is the expected behavior? (add screenshot)

  1. Using the Webpack entry point succeeds, or
  2. Manually configuring the worker succeeds, or
  3. I make a million dollars. millionDollars

What went wrong? (add screenshot)

  1. Manually setting up worker fails: Screenshot_2020-12-25_17-24-47
  2. Webpack entry point fails: Screenshot_2020-12-25_17-23-30
  3. Still no million dollars. crushingStudentDebt

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
merceyzcommented, Dec 30, 2020

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

@Snuffleupagus The issue is that pdfjs-dist lacks an optional(?) peer dependency on worker-loader so Yarn PnP (not Yarn 2) is denying it access

You guys wouldn’t happen to have any leads for me as to why pdfjs-dist seems to be passing “esModule” as worker-loader option, would you? It is indeed true that “esModule” is not one of the options that worker-loader takes. I’ve tried requiring instead of importing, but seeing the same error. Any guidance, appreciated 😃

You’re installing worker-loader@^2 but esModule is a worker-loader@^3 option, granted if pdfjs-dist properly declared its dependencies that would have been avoided

1reaction
jcamdencommented, Dec 30, 2020

Just want to clarify a couple of things for posterity:

  1. To use pdfjs with Yarn PnP, one must add a package extension for pdfjs-dist to yarnrc.yml since pdfjs-dist does not declare its dependencies. In this case, you want worker-loader as a peer-dep (as @merceyz explained above):
packageExtensions:
  'pdfjs-dist@*':
    peerDependencies:
      worker-loader: '^3'
  1. To use pdfjs in any case, note that the global approach (i.e. import pdfjsLib from 'pdfjs-dist/webpack';) evinced in the docs and examples (e.g. here) is now deprecated. It took me some time to sort out why pdfjs was not defined—since my mind was already operating in the realm of worker issues; so I hope to save someone else some time.

I’ve updated the repro repo with the fixes to serve as an example for anyone trying to integrate pdfjs into a Yarn PnP monorepo with webpack 5. That’s the least I can do to pay it forward. Thank you for your awesome contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

worker-loader - webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
@expo/webpack-config | Yarn - Package Manager
Welcome to @expo/webpack-config. Webpack config that's optimized for running universal React and react-native-web projects
Read more >
Webpack 2 not resolving entry point in webpack.config.js
I did this, and I get no error. But why? If I pass PATHS.src to the context parameter, doesn't webpack start at that...
Read more >
webpack-require-from - npm
Webpack plugin that allows to configure path or URL for fetching dynamic imports. Latest version: 1.8.6, last published: a year ago.
Read more >
webpack/webpack - Gitter
I'm using the worker-loader and exports-loader to handle that part. ... I feel like there is something small i'm missing but unsure where...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found