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.

mini-css-extract-plugin can not extract node_module css file

See original GitHub issue
  • Operating System: win7
  • Node Version: v10.12.0
  • NPM Version: 6.4.1
  • webpack Version: 4.29.6
  • mini-css-extract-plugin Version: 0.6.0

image image

Below could build all of my scss files and css files into several stylesheet injections into the html file:

{
    test: /\.(scss|css)$/,
    use: [
        // MiniCssExtractPlugin.loader,
        'style-loader',
        'css-loader',
        'postcss-loader',
        'sass-loader'
    ]
}

Below cound only build one css file but without the node_module css file

{
    test: /\.(scss|css)$/,
    use: [
        MiniCssExtractPlugin.loader,
        'style-loader',
        'css-loader',
        'postcss-loader',
        'sass-loader'
    ]
}

But with “extract-text-webpack-plugin”: “^4.0.0-beta.0” everything behaves as expected. So, i wonder if there is a bug about extracting css file from node_modules?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
BenjaminWFox-Lumediccommented, May 3, 2019

This was the same issue for me as @baremetalfreak mentioned. I changed:

"sideEffects": false, -> "sideEffects": true,

and CSS was correctly emitted.

My issue was that I imported all of my CSS in App.js, import CssTheme from './theme', but never did anything with the imported variable so it was assumed to be unused. I was able to verify that this was the case by just console.log(CssTheme) while I still had "sideEffects": false, in my package.json

0reactions
alexander-akaitcommented, Dec 25, 2019

Answer https://github.com/webpack-contrib/mini-css-extract-plugin/issues/386#issuecomment-489184730

You can mark only css as side effect using this "sideEffects": ["*.css"], in package.json

Read more comments on GitHub >

github_iconTop Results From Across the Web

mini-css-extract-plugin - npm
extracts CSS into separate files. ... Start using mini-css-extract-plugin in your project by running `npm i mini-css-extract-plugin`.
Read more >
MiniCssExtractPlugin - webpack
If false, the plugin will extract the CSS but will not emit the file. It is often useful to disable this option for...
Read more >
Webpack 4: How to extract CSS from Node module?
But adding LESS to my project only to extract styles from an external component seems not right to me. Is there a better...
Read more >
Search - appsloveworld
[Solved]-Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ReferenceError: document is not defined-Reactjs.
Read more >
error: cannot find module 'css-minimizer-webpack-plugin'
First, install the plugin. npm install mini-css-extract-plugin --save-dev.
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