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 bundle is not included when using Webpack 5

See original GitHub issue

Current Behavior

The styles bundle is not included in the dist/.../index.html when using Webpack 5. This happens if there is more than one file in build.styles config of workspace.json.

Expected Behavior

All of the files listed in build.styles are bundled into a single styles.[hash].css and included in the dist/.../index.html file. It worked like this in webpack 4.

Steps to Reproduce

I have created a project to reproduce the problem: https://github.com/markogresak/nx-styles-bug#reproducing-the-problem-with-missing-styles-bundle

It’s a project where I’ve added only some randomly generated css to the output.

Failure Logs

grep css dist/apps/nx-styles-bug/index.html
# <link rel="stylesheet" href="main.79da9420fe0c20301be7.css"></head>

It’s missing the 591.f4af1e18666da591d76a.css, which includes the stylesheets listed in workspace.json under build.styles. Also, the missing file should be named styles.[hash].css.

Environment

nx report

>  NX  Report complete - copy this into the issue template

  Node : 16.4.0
  OS   : darwin x64
  npm  : 7.19.0

  nx : Not Found
  @nrwl/angular : Not Found
  @nrwl/cli : 12.8.0
  @nrwl/cypress : 12.8.0
  @nrwl/devkit : 12.8.0
  @nrwl/eslint-plugin-nx : 12.8.0
  @nrwl/express : Not Found
  @nrwl/jest : 12.8.0
  @nrwl/linter : 12.8.0
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/nx-cloud : Not Found
  @nrwl/react : 12.8.0
  @nrwl/schematics : Not Found
  @nrwl/tao : 12.8.0
  @nrwl/web : 12.8.0
  @nrwl/workspace : 12.8.0
  @nrwl/storybook : 12.8.0
  @nrwl/gatsby : Not Found
  typescript : 4.3.5

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
markogresakcommented, Sep 5, 2021

Great, sorry for the inconvenience. We’ll get both the split chunks and minification fixed soon.

No worries, no inconvenience caused, the workaround was simple. I’ve accepted the fact that webpack 5 support is still new and can have issues. I’m happy to test it out and provide feedback. Thank you for working on Nx and making it available for free, it saves us a lot of time.

1reaction
jaysoocommented, Sep 3, 2021

I have a fix ready for this. Going to see if we can cut a patch release for 12.8.0. We’re also releasing 12.9.0 next week.

In the meantime the only workaround is going back to webpack 4, or you can customize the webpack to remove the optimization.splitChunks.styles entry.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 - some styles are missing in production but exist in ...
javascript - Webpack 5 - some styles are missing in production but exist in development - Stack Overflow. Stack Overflow for Teams –...
Read more >
style-loader - webpack
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 >
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 >
Production | webpack
bundle.js' within webpack configurations do not work as expected. If you're using a library like react , you should actually ...
Read more >
Output Management - webpack
So far we've manually included all our assets in our index.html file, ... and once you start using hashes in filenames and outputting...
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