# Problem Loading CSS from html or js module

**URL:** <https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463>\
**Category:** Help Requests\
**Created:** [May 4, 2020, 3:59pm UTC](https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463 "2020-05-04T15:59:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhysshadow](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/rhysshadow/32/1959_2.png) [@rhysshadow](https://discourse.aurelia.io/u/rhysshadow)\
**Post date:** [May 4, 2020, 3:59pm UTC](https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463/1 "2020-05-04T15:59:20Z")

</div>

I am trying to include a styles.css file in my module to style the size of text boxes and other form inputs.

No matter how I try to include it, it is not being read. When I inspect the items through the developer tools in chrome, I do not see that my styles.css is loaded.

I have tried:

in search.js:

`import './styles.css'; `require( “./styles.css” );`

in search.html:

`<link rel="stylesheet" type="text/css" href="./styles.css" media="screen" />`  
`<require from="./styles.css"></require>`

None of these options have loaded the css.

What am I missing?

---

<div class="post-metadata">

**Author:** ![elitemike](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitemike/32/690_2.png) [@elitemike](https://discourse.aurelia.io/u/elitemike)\
**Post date:** [May 4, 2020, 4:22pm UTC](https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463/2 "2020-05-04T16:22:27Z")

</div>

Are you using webpack?

---

<div class="post-metadata">

**Author:** ![rhysshadow](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/rhysshadow/32/1959_2.png) [@rhysshadow](https://discourse.aurelia.io/u/rhysshadow)\
**Post date:** [May 4, 2020, 4:27pm UTC](https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463/3 "2020-05-04T16:27:10Z")

</div>

Yes, I am using webpack, and I am using this command to run the server:

`au run --host [ipaddress]`

I did discover I’m getting a MIME error that it’s refusing to apply the style because strict MIME checking is set?

---

<div class="post-metadata">

**Author:** ![elitemike](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitemike/32/690_2.png) [@elitemike](https://discourse.aurelia.io/u/elitemike)\
**Post date:** [May 4, 2020, 6:39pm UTC](https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463/4 "2020-05-04T18:39:00Z")

</div>

Make sure your webpack config rules looks something like this, this is only for css

You need to ensure you have the css-loader and style-loader packages installed

```auto
[
      // CSS required in JS/TS files should use the style-loader that auto-injects it into the website
      // only when the issuer is a .js/.ts file, so the loaders are not applied inside html templates
      {
        test: /\.css$/i,
        issuer: [{ not: [{ test: /\.html$/i }] }],
        use: extractCss ? [{
          loader: MiniCssExtractPlugin.loader
        }, ...cssRules
        ] : ['style-loader', ...cssRules]
      },
      {
        test: /\.css$/i,
        issuer: [{ test: /\.html$/i }],
        // CSS required in templates cannot be extracted safely
        // because Aurelia would try to require it again in runtime
        use: cssRules
      },
      { test: /\.html$/i, loader: 'html-loader' },
      { test: /\.ts$/, loader: "ts-loader" },
      // embed small images and fonts as Data Urls and larger ones as files:
      { test: /\.(png|gif|jpg|cur)$/i, loader: 'url-loader', options: { limit: 8192 } },
      { test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff2' } },
      { test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff' } },
      // load these fonts normally, as files:
      { test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'file-loader' },
      {
        test: /environment\.json$/i, use: [
          { loader: "app-settings-loader", options: { env: production ? 'production' : 'development' } },
        ]
      },
      ...when(tests, {
        test: /\.[jt]s$/i, loader: 'istanbul-instrumenter-loader',
        include: srcDir, exclude: [/\.(spec|test)\.[jt]s$/i],
        enforce: 'post', options: { esModules: true },
      })
    ]

```

---

<div class="post-metadata">

**Author:** ![rhysshadow](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/rhysshadow/32/1959_2.png) [@rhysshadow](https://discourse.aurelia.io/u/rhysshadow)\
**Post date:** [May 4, 2020, 8:07pm UTC](https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463/5 "2020-05-04T20:07:14Z")

</div>

My webpack config js looks like this:

```auto
  module: {
    rules: [
      // CSS required in JS/TS files should use the style-loader that auto-injec
ts it into the website
      // only when the issuer is a .js/.ts file, so the loaders are not applied
inside html templates
      {
        test: /\.css$/i,
        issuer: [{ not: [{ test: /\.html$/i }] }],
        use: extractCss ? [{
          loader: MiniCssExtractPlugin.loader
        }, ...cssRules
        ] : ['style-loader', ...cssRules]
      },
      {
        test: /\.css$/i,
        issuer: [{ test: /\.html$/i }],
        // CSS required in templates cannot be extracted safely
        // because Aurelia would try to require it again in runtime
        use: cssRules
      },
      { test: /\.html$/i, loader: 'html-loader' },
      {
        test: /\.js$/i, loader: 'babel-loader', exclude: nodeModulesDir,
        options: tests ? { sourceMap: 'inline', plugins: ['istanbul'] } : {}
      },
      // embed small images and fonts as Data Urls and larger ones as files:
      { test: /\.(png|gif|jpg|cur)$/i, loader: 'url-loader', options: { limit: 8192 } },
      { test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff2' } },
      { test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff' } },
      // load these fonts normally, as files:
      { test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'file-loader' },
      { test: /environment\.json$/i, use: [
        {loader: "app-settings-loader", options: {env: production ? 'production' : 'development' }},
      ]},
    ]
  },

```

When I run ‘au run --host [ip address]’, I see this, which tells me it is trying to extract CSS?

`> webpack-dev-server --extractCss "--host" "[ip address]"`

Does my MIME error that I am getting in the console have anything to do with this problem? It is saying

```auto
Refused to apply style from 'http://[ip address]:8080/styles.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

```

---

<div class="post-metadata">

**Author:** ![Alfhir](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/alfhir/32/1510_2.png) [@Alfhir](https://discourse.aurelia.io/u/Alfhir)\
**Post date:** [May 11, 2020, 8:23am UTC](https://discourse.aurelia.io/t/problem-loading-css-from-html-or-js-module/3463/6 "2020-05-11T08:23:23Z")

</div>

Never had that problem. But it seems seems to happen from time to time:

> <https://stackoverflow.com/questions/48248832/stylesheet-not-loaded-because-of-mime-type>

  

> <https://github.com/froala/angular-froala/issues/170>
>
> i got the following issue after installing froala on my angular app.
> it's not applying the style for some reason :
> any ideas...
