cognitive-engineering-lab / mdbook-quiz

Interactive quizzes for Markdown
http://cel.cs.brown.edu/mdbook-quiz/
Apache License 2.0
106 stars 23 forks source link

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

Closed saferust closed 10 months ago

saferust commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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

saferust commented 10 months ago

It is working fine. Thanks!