mdn / js-examples

Code examples that accompany the MDN JavaScript/ECMAScript documentation
https://developer.mozilla.org/en-US/docs/Web/JavaScript
Creative Commons Zero v1.0 Universal
1.12k stars 699 forks source link

The module example fails due to CORS #14

Closed YagaoDirac closed 1 year ago

YagaoDirac commented 2 years ago

I tried modules/basic-modules/ Nothing displayed in the browser. In F12 console, I see Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///E:/js%20examples%20from%20mdn/js-examples-master/modules/basic-modules/main.js. (Reason: CORS request not http). 2 Module source URI is not allowed in this document: “file:///E:/js%20examples%20from%20mdn/js-examples-master/modules/basic-modules/main.js”.

jesperp commented 2 years ago

You need to load your files through a web server, not directly from the file system (e.g http-server). Also make sure that your web server sets the correct mime type for js files.

schalkneethling commented 1 year ago

Hey @YagaoDirac, as @jesperp states, you must load this using a web server. There are many options for this. One of those is lite-server, which you can find on npmjs.com.

In the future, we recommend that you use either our Discourse forums or StackOverflow for help with code.