Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
Import CSS to Typescript > JS for webpack w/o breaking src JS

I have a module main.ts that calls import './style.css' at the top. This is transpiled to the same import statement in the ES6 emitted by Typescript. I'm running Webpack w/ style-loader on the JS output. This works fine and builds the CSS into the final dist/main.js output.

However, this means that my src/ JS is now broken, as it has this import call at the top. Specifically, when I want to run out of src/ I get this:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/css". Strict MIME type checking is enforced for module scripts per HTML spec.

I don't really want Webpack to be a necessary step in development, only when I deploy. It seems Webpack would follow the linkage if I used require.js, but I'd like to do this without resorting to require(). Is there some kind of meta-syntax or commenting I can use - or forced inclusions in webpack.config.js - to make Webpack include the CSS and let Javascript engines ignore it?

One thing I tried that does work is try { require(['style.css']); } catch (e) {} instead of the import. That way I don't actually need require. It just seems pretty silly.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda