This works when running it locally, haven't tested this yet when running on a live environment. Fortunately, pdfjs-dist also provides a legacy version that works with the old browsers and old bunders (such as Webpack 4). Use workerSrc that you just imported and assign it: Based on past react-pdf filed issues, it seems this occurs when the pdfjs-dist worker version is mismatched with the version react-pdf expects to be using. Import workerSrc from 'pdfjs-dist/build/' Change your Webpack configuration as following: 'path' 'webpack' NormalModuleReplacementPlugin './nodemodules/pdfjs-dist/webpack' 'path' './src/index. Next import the workerSrc in the file where you have to specify it: Use the worker-loader Install worker-loader -save-dev worker-loader Set the pdfjs-dist path Ask Webpack to load pdfjs-dist/webpack when it sees import. It turns out a separate old package I have in my dependencies had also specified an older version of pdfjs-dist in its deps, so two versions were getting installed for me (a newer one by react-pdf and an older one by this other old package). next buil dir is not too you might want to reflect the new versions of Webpack and Next.Import React, , Based on past react-pdf filed issues, it seems this occurs when the pdfjs-dist worker version is mismatched with the version react-pdf expects to be using. Until then I will most likely go with my CopyPlugin solution which works with v12. js,webpack://pdfjs-dist/build/pdf.worker/nodemodules/core-js/modules/iter-call.js,webpack://pdfjs-dist/build/pdf.worker/nodemodules/core-js/modules/. Given asset modules do not seem to be production ready in Next.js 12 yet, the right strategy seems to be waiting for how that experimental feature pans out and then reconsider. Probably related to the fact that URL imports are now experimental in v12 and there is a whole config around their security model: Now even if it all worked, I am not quite sure if using node_modules in the path inside a JSX module is the right thing to do? pdf.worker/nodemodules/core-js/internals/redefine-all.js,webpack://pdfjs-dist/build/pdf.worker/nodemodules/core-js/internals/set-species.js,webpack. For usage with older browsers or environments, without. PDFJS.workerSrc './. PDFJS.workerSrc 'pdfjs-dist/build/' a relative path that'll get resolved and bundled into the same file via webpack & node e.g. It is automatically generated by the build scripts. a Node require spec that'll get resolved and bundled into the same file via webpack & node e.g. Using the one from nodemodules/ doesn't work. This is a pre-built version of the PDF.js source code. Hi, I don't know why, but looks like copy to my project's output folder, or use cdn worker will make the magic happen. Our goal is to create a general-purpose, web standards-based platform for parsing and rendering PDFs. However, the local dev server does not serve files off the root of the build dir, gives 404 back. PDF.js is a Portable Document Format (PDF) library that is built with HTML5. workerUrl.href would then be something like Nice. PS: Care about similar versions of pdf.js and (I use ) when. Webpack 5 would pick up the asset and put. In my case it is possible to use with Angular 6 and CLI with local file. Const workerUrl = new URL('node_modules/pdfjs-dist/build/', ) // no.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |