Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of the box error on first DEV run #12

Closed
netaisllc opened this issue Nov 7, 2018 · 3 comments · Fixed by #36
Closed

Out of the box error on first DEV run #12

netaisllc opened this issue Nov 7, 2018 · 3 comments · Fixed by #36

Comments

@netaisllc
Copy link

netaisllc commented Nov 7, 2018

On a fresh clone, the first npm run dev results in an error loading the app style sheet. The console error is something like this:

Refused to apply style from '{bundles.css blah blah}' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

To work-around it, I built the project (which produces a physical bundles.css file) once, and resumed devving. That seemed to clear the error.

Leaving this open as it could be that I'm missing something fundamental. If not, good to close it.

@frederikhors
Copy link

Same here. Strange enough the style works. It seems webpack-dev-server doesn't serve bundle.css on http://localhost:8080/bundle.css.

@rhernandog
Copy link

rhernandog commented Jul 5, 2019

Same here I want to learn how to use Svelte and before I can write a single line of code I ran into this error.

EDIT

Changing the webpack file to this prevents the issue:

module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader"
        ]
      }
    ]
  },

Of course this is not ideal because of HMR, but prevents the error.

@KieranP
Copy link

KieranP commented Aug 22, 2019

mini css extract plugin seems to support HMR now. This is my config which works great:

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');

const mode = process.env.NODE_ENV || 'development';
const prod = mode === 'production';

module.exports = {
  entry: {
    bundle: ['./src/main.js']
  },
  resolve: {
    alias: {
      svelte: path.resolve('node_modules', 'svelte')
    },
    extensions: ['.mjs', '.js', '.svelte'],
    mainFields: ['svelte', 'browser', 'module', 'main']
  },
  output: {
    path: __dirname + '/public',
    filename: '[name].js',
    chunkFilename: '[name].[id].js'
  },
  module: {
    rules: [
      {
        test: /\.svelte$/,
        exclude: /node_modules/,
        use: {
          loader: 'svelte-loader',
          options: {
            emitCss: true,
            hotReload: true
          }
        }
      },
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: { hmr: !prod }
          },
          'css-loader'
        ]
      }
    ]
  },
  mode,
  plugins: [
    new MiniCssExtractPlugin({
      filename: '[name].css',
      chunkFilename: '[name].[id].css'
    })
  ],
  devtool: prod ? false: 'source-map'
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants