0

I get 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. after importing axios into a javascript file.

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

I though that all I had to do is to run my code on a server (e.g. http://127.0.0.1:8080/) instead of on the file system (e.g. file:///C:/Users/...).

I did that by downloading http-server with npm and ran everything on the above server--but I still get that error.

Edit:

Failed import statement import axios from './node_modules/axios';

David
  • 159
  • 1
  • 14
  • Why don't you use https://www.npmjs.com/package/local-web-server ? It's better! – mindmaster Feb 04 '20 at 17:07
  • No particular reason. After looking for a solution `http-server` was the first thing recommended so I used that. Why is the `local web server` better? – David Feb 04 '20 at 17:10
  • Can you please show the failed import statement? The first coming to mind is, that the file was not found, and the server responded with 404 page (which is HTML). Have you chceked the network tab on the DevTools? – Teemu Feb 04 '20 at 17:12
  • @Teemu--I edited the post with that. – David Feb 04 '20 at 17:15
  • The path is correct? Also I suspect a browser needs a full filename too. – Teemu Feb 04 '20 at 17:17
  • I've tried other variations for the path but this should be the correct one. What do you mean by browser needing a full filename? – David Feb 04 '20 at 17:18
  • The module is saved in a .(m)js file, that file name, including the extension. – Teemu Feb 04 '20 at 17:23
  • Not sure. It is in a `package-lock.json`, `package.json` and in `node_modules` which contains `axios`' code. All are under the same directory. – David Feb 04 '20 at 17:28

1 Answers1

0

You might need type="module" on your script tag. See: https://www.sitepoint.com/using-es-modules/

Ben Lorantfy
  • 963
  • 1
  • 7
  • 19