Skip to content

Using React-PDF with Webpack 5 and Yarn (Berry) #916

Answered by wojtekmaj
wojtekmaj asked this question in Q&A
Discussion options

You must be logged in to vote

By itself, Yarn Berry shouldn't be a problem - you can always use nodeLinker: node-modules to make it completely backwards compatible. However, PnP creates issues with direct references to node_modules directory, because there isn't one.

The trick is to require.resolve pdfjs-dist's package.json - this will give us an easy access to pdfjs-dist virtual folder. This will also work with old node_modules system, so that's actually the recommended way.

So, instead of: node_modules/pdfjs-dist, use path.dirname(require.resolve('pdfjs-dist/package.json')).

pdf.worker.js

CopyWebpackPlugin

You can use CopyWebpackPlugin to copy pdf.worker.js. However, CopyWebpackPlugin will not accept 'node_modules/b…

Replies: 1 comment

Comment options

wojtekmaj
Jan 5, 2022
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by wojtekmaj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #915 on December 29, 2021 09:49.