0

Here's my stack

  • Express
  • Ejs
  • Sass (installed by 'npm install --save-dev sass' - a dev dependency)

I'm getting an error of

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


my head tag is on a separate partials folder:

- views
- - partials
- - - header.ejs
- - index.ejs

my CSS is also on another folder

- public
- - css
- - - style.css
- - - style.css.map
- - - style.scss


my head tag looks like this:

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Learn Web</title>
<base href="/">
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>

I render my index like this:

app.get('/', (req, res) => {
    res.render('index');
})

I tried adding <base href="/">
I tried to omit rel="stylesheet"
I tried to change the type="text/css" to type="text/html" - It got rid of the error but the styles do not apply.


Thank you in advance!

Aplet123
  • 27,379
  • 1
  • 13
  • 35
Ian Natividad
  • 53
  • 1
  • 4

2 Answers2

0

Adding this line to your js file will allow the local css to link: app.use(express.static(__dirname));

You can read about serving static files in Express here: http://expressjs.com/en/starter/static-files.html

-1

So i solved the issue. But it's somehow a half fix. Because I'm just starting my project when I encountered this issue. I restart my project but by using the express-generator where it automatically create an application skeleton. Then after that, I installed Sass using npm and it worked.

Ian Natividad
  • 53
  • 1
  • 4