0
votes

I have read similar questions and the answers all revolved around correcting a line like this:

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

Unfortunately nothing I've read has fixed the issue.

In my index.html I have:

<link rel="stylesheet" href="public/css/style.css">
<script src="public/js/bundle.js"></script>

and in my app.js im using :

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

When I visit the page the console logs

localhost/:1 Refused to apply style from 'http://localhost:3000/public/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

and

GET http://localhost:3000/public/js/bundle.js 404 (Not Found)

localhost/:1 Refused to execute script from 'http://localhost:3000/public/js/bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

1
If I had to guess… you're sending the wrong mime type, and you have strict mime type checking enabled. But I'm just basing that on the error saying that's exactly your problem.Anthony

1 Answers

0
votes

Adding a "/" at the end of public, like so:

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

and removing "public/" in:

<script src="js/bundle.js"></script>
<link rel="stylesheet" href="css/style.css">

fixed the issue.