ES6 modules in local files - The server responded with a non-JavaScript MIME type

前端 未结 7 908
夕颜
夕颜 2020-11-28 07:07

I get this error:

Failed to load module script: The server responded with a non-JavaScript MIME type of \"\". Strict MIME type checking is enforced fo

7条回答
  •  失恋的感觉
    2020-11-28 07:41

    If you got onto this error message, it means that it's not a Same-origin issue.

    As said in the error message, the real problem is that modules scripts require the MIME of your script file to be one of the javascript MIME types.

    Your filesystem doesn't provide any MIME, hence the loading fails.

    So the best solution is obviously to run your code on a local server, and not on the filesystem.

    But since you do insist ;) One workaround is to first fetch your script file as Blob using XHR (fetch can't be used on file:// protocol), then force its type property to be one of js MIMEs, and set your

提交回复
热议问题