While working on implementing my CSS in HTML using NodeJS, Express, and socket.io, I encountered an error message stating:
'Refused to apply style from 'http://localhost:8000/index.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.'
Note: The error only occurs when running on localhost:8000 (Node.js) but not in the normal index.html file.
Here is the configuration in index.js:
var app = express()
.use(SocketIOFileUpload.router)
.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
})
Here is my file structure:
- style
- style.css
- images
- lib
- node_modules
index.html
appConfig.js
index.js
Steps I've taken so far:
- Changed my CSS script from
<link rel="stylesheet" type="text/css" href="style/style.css"/>
into type="text/html"
: it removed the error but the CSS still hasn't been applied in the HTML.
- Checked the spelling of my CSS file name: no issues with the name or the file path
I've searched all over the internet for solutions, but nothing seems to help. It's possible that I misconfigured something since I'm not very familiar with the setup, but I'm out of ideas. Any help or hints would be greatly appreciated. Thank you!