Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Se negó a aplicar el estilo de 'http://localhost:2000/cssFile/style.css' porque es de tipo MIME ('text/html')

Actualmente estoy tratando de agregar mi archivo style.css al archivo home.ejs renderizado por express.js

Pero sigo recibiendo el siguiente error.

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

Mi estructura de archivos es como

 cssFile | style.css views | htmlFile | | home.ejs index.js

Este es mi código express

 const express = require("express"); const app = express(); const path = require("path"); const mongoose = require("mongoose"); const Comments = require("./models/comments"); app.use(express.static(__dirname + "/public")); app.set("views", path.join(__dirname, "views")); app.set("view engine", "ejs"); app.get("/", (req, res) => { res.render("htmlFile/home"); });

Mi casa.ejs:

 ... <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" /> <title>Document</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" /> //buggy code <link rel="stylesheet" type="text/css" href="/cssFile/style.css" /> </head>

He estado buscando otra solución, pero simplemente no puedo resolver la mía.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Mi estructura de archivos es como

 cssFile | style.css views | htmlFile | | home.ejs index.js

Este es mi código express

 ... (all your other code) app.use(express.static(__dirname + "/public"));

En este código JavaScript, le está diciendo a express.static que está tratando de dar servicio a archivos estáticos desde un directorio llamado "público", que no existe. Si mira en el panel "Red" de su navegador, probablemente verá que está recibiendo una página 404 o, a veces, un archivo HTML diferente.

Intente cambiar su estructura de archivos a esto:

 public | cssFile | | style.css views | htmlFile | | home.ejs index.js
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!