question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Styles break after the first change [in wepack 5 / yarn 2](but it works correctly if refresh page manually)

See original GitHub issue

I upgraded my project to Webpack 2 / Yarn 2 and used webpack serve instead of webpack-dev-server to run the dev server. I configured this fast refresh package with webpack 4 before and was OK. I have an issue with the new config, Styles break after the first change. I recorded behavior in this GIF: http://g.recordit.co/1hY0RiTnu5.gif Styles break after the first change

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
pmmmwhcommented, Nov 18, 2020

@gaearon I don’t know if the issue is Webpack or fast refresh plugin. I updated all loaders and webpack plugins. I don’t know how to reproduce it without this plugin to sure webpack built-in HMR has a style issue, do you have any idea to reproduce it without the plugin? Maybe this issue is related to MiniCssExtractPlugin. This is my style-loader config:

[
  {
    test: /\.s?[ac]ss$/,
    exclude: /\.module.s?[ac]ss$/,
    use: [
      {
        loader: MiniCssExtractPlugin.loader,
        options: {
          esModule: true,
        },
      },
      'css-loader',
      'postcss-loader',
      { loader: 'sass-loader', options: { sourceMap: !isProduction } },
    ],
  },
  {
    test: /\.less$/,
    use: [
      {
        loader: MiniCssExtractPlugin.loader,
        options: {
          esModule: true,
        },
      },
      'css-loader',
      {
        loader: 'less-loader', // compiles Less to CSS
        options: {
          lessOptions: {
            modifyVars: lessVariable,
            javascriptEnabled: true,
          },
        },
      },
    ],
  },
  {
    test: /\.module.s?[ac]ss$/,
    use: [
      {
        loader: MiniCssExtractPlugin.loader,
        options: {
          esModule: true,
        },
      },
      {
        loader: 'css-loader',
        options: {
          importLoaders: 1,
          modules: {
            localIdentName: sharedConfig.styleLoader.modules.localIdentName,
          },
        },
      },
      'postcss-loader',
      { loader: 'sass-loader', options: { sourceMap: !isProduction } },
    ],
  },
]

Dependencies:

{
  "react": "^17.0.1",
  "react-dom": "^17.0.1",
  "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
  "react-refresh": "0.9.0",
  "webpack": "^5.4.0",
  "webpack-cli": "^4.2.0",
  "postcss-loader": "^4.0.4",
  "node-sass": "^5.0.0",
  "mini-css-extract-plugin": "^1.3.1",
  "less-loader": "^7.1.0",
  "less": "^3.12.2",
  "css-loader": "^5.0.1",
  "babel-loader": "^8.2.1",
  "@babel/cli": "^7.12.1",
  "@babel/core": "^7.12.3",
  "@babel/node": "^7.12.6",
  "sass": "^1.29.0",
  "sass-loader": "^10.1.0"
}

Hi - I am pretty certain that your error has nothing to do with this plugin.

To achieve HMR with CSS during development - you will have to use style-loader instead of MiniCssExtractPlugin.loader. You could probably switch them according to Webpack’s mode. Alternatively, you can use extract-css-chunks-webpack-plugin which basically combines the two as one plugin.

Docs here: https://github.com/webpack-contrib/css-loader#extract

0reactions
pmmmwhcommented, Jun 27, 2021

@mizi-lin If you have any issues related to CSS, please file issues at the corresponding loaders (e.g. style-loader, css-loader, etc.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solution for Webpack 5 Dev Server Not Live Reloading
There is currently a bug with Webpack 5 and webpack-dev-server not working that is caused by the existence of a browserslist in the...
Read more >
webpack-dev-server hot reload not working - Stack Overflow
And it builds and seems like it's working. localhost:8080 shows the expected result but hot-reload does just not work. When I change a...
Read more >
To v5 from v4 - webpack
This guide aims to help you migrating to webpack 5 when using webpack directly ... in your webpack 4 configuration and check if...
Read more >
Get started with Vuetify
Vue UI install. Vuetify can also be installed using Vue UI, the new visual application for Vue CLI. Ensure that you have the...
Read more >
webpack Tutorial: How to Set Up webpack 5 From Scratch
This will allow modules to update without doing a complete reload of the page - so if you update some styles, just those...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found