Thalapathy
Thalapathy

Reputation: 147

Failed to load module script - importing classes in index.html

I am trying to load these two classes and I get the below error:

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

<script type="module">
    import { A, B } from './js/dist/loader';
</script>

<body>
   <div ng-view></div>

   <script src="js/lib.js"></script>
   <script src="js/main.js"></script>
   <script src="js/build/app.js"></script>
</body>

Upvotes: 0

Views: 1397

Answers (1)

pckessel
pckessel

Reputation: 31

From MDN: "To get modules to work correctly in a browser, you need to make sure that your server is serving them with a Content-Type header that contains a JavaScript MIME type such as text/javascript. If you don't, you'll get a strict MIME type checking error along the lines of "The server responded with a non-JavaScript MIME type" and the browser won't run your JavaScript."

I would probably start by taking a look at the header your server is sending over when delivering the pages.

Upvotes: 1

Related Questions