'NodeJS app can't work because of dependencies script being blocked due to MIME type error

my teammates and I are currently developing a web game with babylonjs and we need to deploy it on heroku. So I created a file app.js to be the "server" side, here is the code:

const express = require('express');

const app = express();

const PORT = process.env.PORT || 3000;

app.use(express.static(__dirname + '/public'));

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, '/public/index.html'));
});

app.listen(PORT, () => {
    console.log('App is running');
});

I also created a /public directory where are located css files, js scripts and the index.html

Here is my index.html

<!DOCTYPE html>
<html>
    <head>
    <title>Wyrunique</title>
    <meta charset="UTF-8">
        <link rel="stylesheet" href="css/default.css">
        <script src="node_modules/babylonjs/babylon.max.js"></script>
        <script src="node_modules/babylonjs-gui/babylon.gui.js"></script>
        <script src="node_modules/babylonjs-loaders/babylonjs.loaders.js"></script>
        <script src="lib/cannon.js"></script>
        <script type="module" src="js/Wyrunique.js"></script>
    </head>
    <body>
        <canvas id="myCanvas" width=1920 height=1080></canvas>
    </body>
</html>

Along with those there is the Procfile required by heroku.

All my babylon dependencies and express are specified in the "dependencies" section of my package.json. The "main" in the same file is my app.js file. And the start script is node app.js

My workspace is organized as such

/
-> assets/
-> lib/
-> node_modules/
-> public/
---> css/
---> js/
---> index.html
-> app.js
-> package.json
-> Procfile

So my heroku app is running but nothing is displayed because I have the error:

The resource from “https://lost-in-yourself.herokuapp.com/node_modules/babylonjs-loaders/babylonjs.loaders.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

I got this for all the babylon dependencies and for the cannon.js file which is in the lib dir.

I have checked also the localhost version and it does not work as well for the same reasons.

I am pretty sure it is for a dumb reason but I'm not able to find it. Can someone help ? Thank you for your time



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source