Failed to load module script because of a disallowed MIME type

user5222086

Consider the following file structure and content:

js
└─ test
    ├─ modules
    │  └─ math.mjs
    └─ main.mjs

math.mjs:

export function square(v) { return v * v; }

main.mjs:

import { square } from './modules/math.mjs';
console.log(square(2));

On a simple page at http://server.local/module-test (through Apache web server), I'm trying to load the main.mjs:

<script type="module" src="http://server.local/js/test/main.mjs"></script>

but the browsers keep complaining about the MIME type, for example:

Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.

I've tried other relative-references (through /, ./ and ../) on the import statement to no avail!

So, what I've missed to have it working?

Ouroborus

One of the conditions for a module to be loaded by the browser is that the server serves the module with a MIME type of application/javascript (or other appropriate MIME type depending on language and browser support; there's a new type javascript/esm for javascript modules that has mixed support). This means configuring the server provide a response header that includes at least Content-Type: application/javascript for javascript modules (or javascript in general).

From the error you're getting, it seems your server is either providing an empty Content-Type header or not providing it at all. This usually happens when trying to load modules from a file:// url, without a server, but can happen with a mis-configured server.

It's likely that the file extension .mjs is unrecognized by the server so its unable to serve it with the right MIME type.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Loading module was blocked because of a disallowed MIME type (“application/wasm”)

From Dev

Module blocked because of a disallowed MIME type (“text/html”)

From Dev

Blocked because of disallowed mime type ("text/html")

From Dev

Node server: Loading module was blocked because of a disallowed MIME type (“text/html”)

From Dev

Failed to load module script: The server responded with a non-JavaScript, CSS MIME type of "text/x-scss"

From Dev

Nginx was blocked because of a disallowed MIME type (“text/html”). Angular 8

From Dev

GCP App Engine / Angular - Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html"

From Java

Blocked because of a disallowed MIME type (“text/html”) : Angular 8 deployed on tomcat 9.0.30 fails to serve the assets

From Dev

Angular 8 inside of ASP Net Core was blocked because of a disallowed MIME type (“text/html”)

From Dev

Refused to execute script because strict MIME type checking is enabled

From Dev

How to address error "Did not load script at 'script name' because non script MIME types are not allowed when 'X-Content-Type: nosniff' is given

From Dev

Cannot load the script with the type "module"

From Dev

Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

From Dev

Refused to execute script from '*' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

From Dev

Failed to register a ServiceWorker: The script has an unsupported MIME type - reactjs

From Dev

DOMException: Failed to register a ServiceWorker: The script does not have a MIME type

From Dev

Refused to execute script from URL because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

From Dev

Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

From Dev

html view can not load css style because of MIME-type error

From Dev

Could not load javascript file because of wrong MIME-Type (Spring Boot 2, Thymeleaf, Bootstrap)

From Dev

CSS can't load because of MIME type on one page, but works fine on another page

From Dev

Refused to execute *path_to_bundle* as script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type

From Dev

Webpack dev server throws error - Refused to execute script because its MIME type ('text/html') is not executable

From Dev

Importing jQuery plugin into Angular 2+ Refused to execute script because its MIME type ('text/html') is not executable

From Dev

Refused to execute script from '*.ts' because its MIME type ('video/vnd.dlna.mpeg-tts') is not executable

From Dev

Refused to execute script from 'url' because its MIME type ('image/jpeg') is not executable

From Dev

Express routing static file: Failed to load module script

From Dev

Failed to load module script when importing a .jpg file in a javascript file

From Dev

How to fix: "Failed to load module script ..." Angular 8, Electron 5

Related Related

  1. 1

    Loading module was blocked because of a disallowed MIME type (“application/wasm”)

  2. 2

    Module blocked because of a disallowed MIME type (“text/html”)

  3. 3

    Blocked because of disallowed mime type ("text/html")

  4. 4

    Node server: Loading module was blocked because of a disallowed MIME type (“text/html”)

  5. 5

    Failed to load module script: The server responded with a non-JavaScript, CSS MIME type of "text/x-scss"

  6. 6

    Nginx was blocked because of a disallowed MIME type (“text/html”). Angular 8

  7. 7

    GCP App Engine / Angular - Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html"

  8. 8

    Blocked because of a disallowed MIME type (“text/html”) : Angular 8 deployed on tomcat 9.0.30 fails to serve the assets

  9. 9

    Angular 8 inside of ASP Net Core was blocked because of a disallowed MIME type (“text/html”)

  10. 10

    Refused to execute script because strict MIME type checking is enabled

  11. 11

    How to address error "Did not load script at 'script name' because non script MIME types are not allowed when 'X-Content-Type: nosniff' is given

  12. 12

    Cannot load the script with the type "module"

  13. 13

    Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

  14. 14

    Refused to execute script from '*' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

  15. 15

    Failed to register a ServiceWorker: The script has an unsupported MIME type - reactjs

  16. 16

    DOMException: Failed to register a ServiceWorker: The script does not have a MIME type

  17. 17

    Refused to execute script from URL because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

  18. 18

    Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

  19. 19

    html view can not load css style because of MIME-type error

  20. 20

    Could not load javascript file because of wrong MIME-Type (Spring Boot 2, Thymeleaf, Bootstrap)

  21. 21

    CSS can't load because of MIME type on one page, but works fine on another page

  22. 22

    Refused to execute *path_to_bundle* as script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type

  23. 23

    Webpack dev server throws error - Refused to execute script because its MIME type ('text/html') is not executable

  24. 24

    Importing jQuery plugin into Angular 2+ Refused to execute script because its MIME type ('text/html') is not executable

  25. 25

    Refused to execute script from '*.ts' because its MIME type ('video/vnd.dlna.mpeg-tts') is not executable

  26. 26

    Refused to execute script from 'url' because its MIME type ('image/jpeg') is not executable

  27. 27

    Express routing static file: Failed to load module script

  28. 28

    Failed to load module script when importing a .jpg file in a javascript file

  29. 29

    How to fix: "Failed to load module script ..." Angular 8, Electron 5

HotTag

Archive