Skip to content

fix(bundling): prevent treeshaking of CSS modules in extract mode#34830

Open
FrozenPandaz wants to merge 1 commit intomasterfrom
fix/34776-css-extraction-treeshake
Open

fix(bundling): prevent treeshaking of CSS modules in extract mode#34830
FrozenPandaz wants to merge 1 commit intomasterfrom
fix/34776-css-extraction-treeshake

Conversation

@FrozenPandaz
Copy link
Collaborator

Current Behavior

When using @nx/rollup with CSS extraction (the default), CSS files imported from JavaScript are silently dropped from the build output. The postcss plugin's transform hook replaces CSS imports with export default {} — a side-effect-free module that Rollup treeshakes away. When the generateBundle hook later scans chunk modules for extracted CSS, the treeshaken modules are gone, so no CSS is emitted.

This is a regression introduced in #34110 which replaced the external rollup-plugin-postcss with an inlined version.

Expected Behavior

CSS files imported from JavaScript should be extracted and emitted in the dist folder, regardless of Rollup's treeshaking behavior. The fix adds moduleSideEffects: true to the transform return value for CSS files, which tells Rollup to keep these modules in the bundle since CSS imports are inherently side-effectful.

Related Issue(s)

Fixes #34776

The postcss plugin's transform hook returns an empty export for CSS files
in extract mode, which Rollup treeshakes away. This causes the
generateBundle hook to miss the CSS content entirely, resulting in no CSS
files in the dist output.

Adding moduleSideEffects: true to the transform return tells Rollup to
keep CSS modules in the bundle regardless of whether their exports are
used, since CSS imports are inherently side-effectful.

Fixes #34776
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner March 14, 2026 01:46
@FrozenPandaz FrozenPandaz requested a review from JamesHenry March 14, 2026 01:46
@netlify
Copy link

netlify bot commented Mar 14, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 2e05f0d
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69b4be0c10ea7f0008cf122e
😎 Deploy Preview https://deploy-preview-34830--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Mar 14, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 2e05f0d
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69b4be0c5f0792000802c95e
😎 Deploy Preview https://deploy-preview-34830--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Mar 14, 2026

View your CI Pipeline Execution ↗ for commit 2e05f0d

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 49m 12s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 47s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-14 02:40:46 UTC

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 this pull request may close these issues.

Css files are not emitted anymore using rollup

1 participant