I'm serving up some static files like images and fonts, without any problem. When I try to do the same with a PDF file, I get an Error.
ERROR in ./src/views/default/components/Footer.js
c:Resurs
eposFrontendsrcviewsdefaultcomponentsFooter.js
5:17 error Parse errors in imported module 'src/includes/ANVANDARAVTAL_MITTKONTOR.pdf' import/default
? 1 problem (1 error, 0 warnings)
ERROR in ./src/views/default/components/Footer.js
Module not found: Error: Cannot resolve module 'application-loader' in c:Resurs
eposFrontendsrcviewsdefaultcomponents
@ ./src/views/default/components/Footer.js 21:32-84
The webpack config works fine, with all the loaders for jsx, es6, css, static files... except for the loader config for PDF.
{
test: /.pdf(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader?minetype=application/pdf&name=[name].pdf'
}
My other loader config, that works, looks virtually the same for PDFs, AND WORKS... WHY (SOBBING)!? Ex:
{
test: /.(ttf|eot|svg)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'file-loader'
}
The import of files into react component looks like this:
import bg from "src/design/images/loginBG.jpg"; //works fine
import pdf from "src/includes/ANVANDARAVTAL_MITTKONTOR.pdf"; //NOT WORKING!
I've tried so many configurations, googled the error, googled for loaders that could solve the problem. Nothing about serving static content from webpack/react, except the usual images, css, js.
I also tried serving a txt file just to see if it works. This also fails with the same error as the PDF.
Why does webpack try to parse the files when using the file loader?
See Question&Answers more detail:
os