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?
.mjs
files with an appropriate javascript MIME type, or simply try using.js
file extension. – Clunk