Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
Importing js file as module in html gives CORS errors in firefox

I have a simple html file:

<html>
  <head>
    <meta charset="utf-8"/>
    <title>Test</title>
  </head>
  <script type="module">
    import init from './target/test.js'
    init()
  </script>
</html>

And in the target folder a test.js file:

function init() {
    console.log("It works");
}

export default init;

But when I open the html file with firefox I get the following errors in the console:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/Users/wanne/Bureaublad/hmm/target/test.js. (Reason: CORS request not http).
Module source URI is not allowed in this document: “file:///C:/Users/wanne/Bureaublad/hmm/target/test.js”.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to this article, running modules require a HTTP(s) connection and will not work locally:

If you try to open a web-page locally, via file:// protocol, you’ll find that import/export directives don’t work. Use a local web-server, such as static-server or use the “live server” capability of your editor, such as VS Code Live Server Extension to test modules.

So I'd suggest exactly that and instead of running it locally, use a live server extension from your preferred text editor.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!