-
Greetings everyone. I'll try and stay short and to the point. In webpack.config.js, this is our module section: module: {
rules: [
{
test: /node_modules\/pdfjs-dist.*\.js$/gi, // this is the newly added object for
use: ['file-loader'] // the file-loader module
},
{
test: /\.(ts|tsx|js|jsx|mdx)$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: { transpileOnly: true }
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(sass|scss)$/,
use: ['style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
test: /\.(jpeg|jpg|png|gif|svg|eot|ttf|woff|woff2)$/,
use: [
{
loader: 'url-loader',
options: { limit: 100000 }
}
]
}
]
}, In my PDFViewer.jsx component (truncated for brevity) import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
// note, URL is a fully-qualified pdf on a cdn; it requires no CORS of any kind
// and it works fine when pasted into an incognito window
<Document file={url} onLoadSuccess={onDocumentLoadSuccess}>
<Page pageNumber={pageNumber} />
</Document> But I end up getting this console error in Google Chrome: I have tried every combination of file-loader and url-loader that I can think of. But it seems nothing makes a difference. It's always the same error message. Obviously other local static files work fine, like images and fonts. But loading the pdf.worker.js file I just can't grasp. I feel like I must be missing something very obvious (and something I had thought importing from I would love any help anyone can give me. All of the answers online seem to refer to loading local static PDFs. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I don't believe the file-loader rule for pdfjs-dist stuff is necessary. At least that's not what I do in Webpack 4 sample app. |
Beta Was this translation helpful? Give feedback.
OK. Well finally, I was able to get this to work by doing my own network request for the file as a blob, setting that blob result in state, and then passing that state to the 's file prop. Works like a charm.
Sorry to have bothered you with all this. But it was helpful!