The Error “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.”, is an error that is invoked when you are working on a website that uses gulp
to compile and use a style. Given below is the snippet of the error you might get:
MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
I would like to share with you the steps I took to fix the “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.”
Why “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.” Error is Seen?
The error, “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.” is seen because, you must have set an incorrect URL to the file or when your server is not properly configured.
In the result, the browser does not get the stylesheet, but it gets some HTML with 404 status and with the “Content-Type” header.
The error is also caused when you use angular and do not add css file to the styles packaging in the angular.json.
The detailed solution to fix the error “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.”, is given below:
How to fix “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.” Error?
To fix the error, for node.js, you will have to make sure that /public does not have a forward slash at the end, so you will have to include that in the href option of your HTML. Once configuration is changed, MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled error would be fixed.
To fix the error, “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.”, you will have to follow the below mentioned steps:
The first step for a Node.js applications you will have to re-check your configuration, by using the below mentioned code as a refrence:
app.use(express.static(__dirname + '/public'));
Make a note that /public
does not have a forward slash at the end, so you will have to include that in the href option of your HTML, you can use the below mentioned code as a refrence:
href="/css/style.css">
In case you do not wish to include a forward slash (/public/
) then you can just do href="css/style.css"
.
In case you still face this error then it is most likely that you are defining your error in a wrong way, like the code mentioned below:
<link rel="stylesheet" href="styles.css">
In the href section you have refer to your CSS file properly to avoid the error.
This should fix the error, “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.”
Conclusion
To fix the error “MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.”, for node.js using applications you will have to re-check your configurations.
You will have to make sure that /public does not have a forward slash at the end, so you will have to include that in the href option of your HTML.