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

1.1K
Views
Failed to load module script: Expected a JavaScript module script

Console writes following "Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec". I am pretty sure I am doing everything right, server sets header to "text/javascript" when answering request. I explictly console.log what I specify in writeHeader and there is "text/javascript" but browser for some reason shows hollow string "".

HTML:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="./StylesCSS/main-style.css">
    </head>
    <body>
        DOC
        <script type="module" src="./JScripts/init.js"></script>
    </body>
</html>

SERVER:

const fs = require("fs");
const http = require("http");
let { _mainMap } = require("./addresses");

const server = http.createServer((req, res) => {
    console.log(req.url);
    let _currentReq;
    if (_currentReq = _mainMap.get(req.url))
    {
        console.log(_currentReq[1]);
        res.writeHeader(200, "Content-Type", _currentReq[1]);
        fs.readFile(_currentReq[0], (err, data) => {
            if (err) console.log("READ_FILE::ERROR");
            res.write(data);
            res.end();
        });
    } else 
    {
        res.writeHeader(404, "Content-Type", "text/html");
        fs.readFile(__dirname + "/../404.html", (err, data) => {
            if (err) console.log("READ_FILE::ERROR");
            res.write(data);
            res.end();
        });
    }
});

server.listen(8080, () => {
    console.log("LISTENING_TO_PORT_8080");
});

//-----------------------------ANOTHER-MODULE----------------------------------------------

let _dir = __dirname;
let _mainMap = new Map();

module.exports = {
    _mainMap: _mainMap
};

//easy to init arr
let _hashArr = [
    ["/", _dir + "/../main.html", "text/html"],
    ["/JScripts/init.js", _dir + "/../JScripts/init.js", "text/javascript"],
    ["/StylesCSS/main-style.css", _dir + "/../StylesCSS/main-style.css", "text/css"]
];

//copy values from _hashArr to _mainMap
for (let i = 0; i < _hashArr.length; i++)
{
    _mainMap.set(_hashArr[i][0], [_hashArr[i][1], _hashArr[i][2]]);
}

init.js file itself is blank

about 4 years ago · Juan Pablo Isaza
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!