admin管理员组文章数量:1327301
I try to use pdfjs in a small typescript app with parceljs as bundler, but when I load the worker with:
pdfjsLib.GlobalWorkerOptions.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js';
I get this error in the Firefox console:
pdf.worker.min.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type
and the worker is not loaded.
If I load the worker like this:
pdfjsLib.GlobalWorkerOptions.workerSrc = `.js/${(pdfjsLib as any).version}/pdf.worker.min.js`;
everything works fine.
I have looked at the MDN description of the error and I sounds like some server side thing, so is it a limitation of the parcel server and is there a workaround?
I try to use pdfjs in a small typescript app with parceljs as bundler, but when I load the worker with:
pdfjsLib.GlobalWorkerOptions.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js';
I get this error in the Firefox console:
pdf.worker.min.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type
and the worker is not loaded.
If I load the worker like this:
pdfjsLib.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare./ajax/libs/pdf.js/${(pdfjsLib as any).version}/pdf.worker.min.js`;
everything works fine.
I have looked at the MDN description of the error and I sounds like some server side thing, so is it a limitation of the parcel server and is there a workaround?
Share Improve this question asked Mar 26, 2019 at 9:27 Jørgen RasmussenJørgen Rasmussen 1,36321 silver badges37 bronze badges2 Answers
Reset to default 3Check the file permissions of that .js file on your websever.
I had a similar issue where loading one of my .js files failed and Firefox printed the message:
The script from “https://my.website./file.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
Loading failed for the
<script>
with source “https://my.website./file.js”.
All other .js files were sent with the correct content-type "application/javascript", but this one file was sent with "text/html".
The problem was, that while transferring the file to my webserver (using FileZilla) the permissions of the file were set to 600. Setting the file permissions to 705 fixed it. The .js file is now sent with the correct content-type and the Firefox message is gone.
It's happening because of the wrong content-type response header.
Your server is responding with a javascript file with content-type: "text/html" which is wrong.
Change the content-type to "text/javascript".
It should work fine.
Update (11-APR-2019):
I am assuming you are using express framework for http-server. content-type can be set using a middleware.
app.use('*.js', (req, res, next) => {
res.set('Content-Type', 'text/javascript')
next();
})
Add this before the static file serving middleware.
本文标签:
版权声明:本文标题:pdf.js - Why do I get a "df.worker.min.js” was loaded even though its MIME type (“texthtml”) is not a valid JavaScript 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742203661a2432417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论