0

This is the error I am getting.

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

This is my index.js file

//Requiring Dependencies
const express = require('express');
const app = express();

const mongoose = require('mongoose');

const path = require('path');

//To run and parse EJS
const engine = require('ejs-mate');

//Using EJS-Mate
    app.engine('ejs' , engine);
    app.set('view engine' , 'ejs');
    app.set('views' , path.join(__dirname, 'views'));

    app.use(express.urlencoded({extended: true}));

    //For use of files like js and css in public directory
    app.use(express.static(path.join(__dirname, './public')))

    app.get('/' , (req , res) => {

    })

    app.get('/home' , (req , res) => {
        res.render('layouts/boilerplate')
    })

This is the boilerplate.ejs where i want to add the stylesheet

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <base href="/">
    <title>BoilerPlate</title>

    
    <link rel="stylesheet" type="text/css" href="/public/stylesheets/style.css">

    <!-- BOOTSTRAP CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

</head>
<body>
        
    <!-- NAVBAR -->
    <%- include('../partials/navbar.ejs') %>


<!--BOOTSTRAP Javascript-->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
    integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
    crossorigin="anonymous"></script>
    
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
    integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
    crossorigin="anonymous"></script>
</body>
</html>

The bootstrap CSS however is working. So I tried removing the "rel" error goes but the stylesheet is not applied. I also tried to use the base method and still did not work, also added type=text/css, and still didn't work. Any idea why it is not working?

4
  • Does this answer your question? MIME type error with express.static and CSS files Commented Nov 12, 2021 at 0:50
  • TL;DR use href="/stylesheets/style.css" (no /public prefix) Commented Nov 12, 2021 at 0:51
  • Works @Phil , I appreciate it . Commented Nov 12, 2021 at 1:10
  • This is what dev tools are for, too: remember to look at your network tab, not just the console tab, because the network tab would have told you that your CSS file didn't have a 200 status code, but a 404, with the response being an HTML page. Commented Nov 13, 2021 at 20:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.