Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading module was blocked because of a disallowed mime type #40

Closed
saferust opened this issue Dec 21, 2023 · 3 comments
Closed

Loading module was blocked because of a disallowed mime type #40

saferust opened this issue Dec 21, 2023 · 3 comments

Comments

@saferust
Copy link

saferust commented Dec 21, 2023

I've encountered an issue with the .mjs file type while using mdbook quiz. When I open a page containing the quiz and test it through a server I get the following errors in different browsers:

Firefox:

Loading the module from https://xxx/mdbook/quiz/quiz-embed.mjs was blocked due to a disallowed MIME type.

Microsoft Edge:

Failed to load module script: Expected a JavaScript module script, but the server responded with a MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.

To resolve this issue the server must serve the .mjs file appropriately. However, when you don't have control over the server or are publishing files for public use, this can lead to problems (as I am here). Some tools may also not support the .mjs extension.

A workaround to make the quiz-embed.mjs module work is to append .js to the end of .mjs files, like quiz-embed.mjs.js. This is accepted but it requires manual replacement of all artifacts in the generated code.

Is there a reason for using the .mjs file extension?

If it was for module clarity, preferred over .js, one could use .mjs during development and convert to .js during the build step. However, ensure that changing to a .js file does not introduce additional issues. Currently this workaround is working for me without any issues.


@willcrichton
Copy link
Collaborator

There's not a particular reason -- it should be an IIFE target anyway with a .js extension. I will merge #41 and make a release soon that should fix this for you.

@willcrichton
Copy link
Collaborator

Just released v0.3.4. Please update and close this issue if it fixed your problem.

@saferust
Copy link
Author

saferust commented Jan 3, 2024

It is working fine. Thanks!

@saferust saferust closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants