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.

Webpack 4 does not process css files from node_modules in production mode

See original GitHub issue

Bug report

DISCLAIMER: this issue is a duplicate of #8782. The original issue was closed without (as I can see) any strong reason. I asked to reopen the original issue, but, unfortunately, did not hear back. This bug is stopping us from migrating to webpack 4 from 3 (it works correctly in webpack 3). It will be great if someone can take a look.

What is the current behavior? I’m importing css files from a third party library (installed in node_modules) into my main entry point. When I run webpack in development mode, the css files are correctly processed and extracted into the separate css file. However, in production mode the css files are not processed at all.

Webpack output in development mode: screen shot 2019-02-19 at 11 12 25 am As you can see it has styles.css and styles.index.js

Webpack output in production mode: screen shot 2019-02-19 at 11 13 16 am As you can see it does not have styles.css and styles.index.js

If the current behavior is a bug, please provide the steps to reproduce. Please take a look at GitHub repository

The repo has two absolutely identical configs except for mode property. I’m aware that it is not recommended to use split chunks in development mode. The purpose to have dev and prod configs identical is to illustrate that only difference in mode affects which files has been processed by webpack and which not.

Run:

yarn install

yarn build
yarn build:dev

Check the output of those commands. The webpack that run in development has a css files in the output, while the one that was in production does not.

What is the expected behavior? Webpack should process css files from node_modules that are imported into entry point in development and production modes.

Other relevant information: webpack version: 4.28.4 Node.js version: 11.6.0 Operating System: macOS Mojave Additional tools: yarn 1.13.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

10reactions
sokracommented, Feb 19, 2019

You config is correct.

Actually this is working as expected, I can tell you why. (It is a bug in blueprintjs though)

You imported the styles with import '@blueprintjs/core/lib/css/blueprint.css'; but do no use any export of them.

@blueprintjs/core has "sideEffects": false in its package.json, which means: “No module has a side effect”.

As you don’t use exports of import '@blueprintjs/core/lib/css/blueprint.css'; and it has no side-effects, webpack is allowed to drop the import while optimizing.

You can change the package.json to "sideEffects": ["*.css"],, which means: “Only .css files have side effects” and it will work correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css-loader | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Cannot load css file in webpack 4 - Stack Overflow
1 Answer 1 · Actually, MiniCssExtractPlugin.loader is required if you want to remove css from bundles and have them into separate files, which...
Read more >
How to configure CSS and CSS modules in webpack
One of the first thing you need to configure in your webpack project is CSS. CSS is so fundamental to a web app...
Read more >
How to configure CSS Modules for webpack - LogRocket Blog
Increase the flexibility of your app's CSS components with CSS Modules and Webpack in this handy tutorial and demo app build.
Read more >
mini-css-extract-plugin - npm
This can be achieved by using the mini-css-extract-plugin , because it creates separate css files. For development mode (including webpack-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