Skip to content

fix(webpack): disable extractComments on the swc terser minimizer - #36238

Merged
leosvelperez merged 1 commit into
masterfrom
gh-36233
Jul 14, 2026
Merged

fix(webpack): disable extractComments on the swc terser minimizer#36238
leosvelperez merged 1 commit into
masterfrom
gh-36233

Conversation

@leosvelperez

Copy link
Copy Markdown
Member

Current Behavior

Production builds using @nx/webpack:webpack with compiler: 'swc' and optimization enabled crash during minification once terser-webpack-plugin resolves to 5.6.x:

ERROR in main.js
main.js from Terser plugin
unknown field `extractComments`, expected one of `parse`, `compress`, `mangle`, `format`, `output`, `ecma`, ...

The babel compiler path sets extractComments: false on its TerserPlugin, but the swc path did not.

Expected Behavior

compiler: 'swc' production builds minify successfully, consistent with the babel path.

Related Issue(s)

Fixes #36233

Implementation Details

terser-webpack-plugin 5.6 changed its swc minifier to forward the plugin-level extractComments option (default true) into @swc/core's minify() options. @swc/core rejects extractComments as an unknown field, so any swc production build using Nx's default minimizer throws. Only extractComments: false avoids the forward, since the plugin skips it only when the value is exactly false.

The fix sets extractComments: false on the swc TerserPlugin, mirroring the babel branch. Verified against a real webpack build: on 5.6.1 the crash disappears, and the emitted bundle is byte-identical to the output on the previously pinned 5.3.x (which ignored the option), so there is no behavior change beyond removing the crash.

The trigger is the terser-webpack-plugin 5.6 bump, not a specific webpack version; the crash reproduces on webpack 5.105.x as well.


View session information ↗

Production builds with `compiler: 'swc'` crashed during minification once
terser-webpack-plugin resolved to 5.6.x:

  unknown field `extractComments`, expected one of `parse`, `compress`, `mangle`, ...

terser-webpack-plugin 5.6 forwards the plugin-level `extractComments` option
(default `true`) into @swc/core's minify options, which rejects it as an
unknown field. The babel minimizer branch already set `extractComments: false`;
the swc branch did not, so it inherited the crashing default.

Set `extractComments: false` on the swc `TerserPlugin` to match the babel
branch. On the previously pinned 5.3.x (which ignored the option) the emitted
output is byte-identical, so this only removes the crash on 5.6+.

Add a unit test asserting both minimizer branches set `extractComments: false`.
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 840ced2
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a4ba607f527ed000760f2f4
😎 Deploy Preview https://deploy-preview-36238--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

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 840ced2
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a4ba60800c729000939f9e2
😎 Deploy Preview https://deploy-preview-36238--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

nx-cloud Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 840ced2

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 6m 27s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 4s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 1m 2s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 18s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-06 13:58:46 UTC

@leosvelperez leosvelperez self-assigned this Jul 6, 2026
@leosvelperez
leosvelperez marked this pull request as ready for review July 6, 2026 14:03
@leosvelperez
leosvelperez requested a review from a team as a code owner July 6, 2026 14:03
@leosvelperez
leosvelperez requested a review from AgentEnder July 6, 2026 14:03
@leosvelperez
leosvelperez merged commit 4a63779 into master Jul 14, 2026
27 of 28 checks passed
@leosvelperez
leosvelperez deleted the gh-36233 branch July 14, 2026 07:29
FrozenPandaz pushed a commit that referenced this pull request Jul 20, 2026
…6238)

## Current Behavior

Production builds using `@nx/webpack:webpack` with `compiler: 'swc'` and
optimization enabled crash during minification once
`terser-webpack-plugin` resolves to 5.6.x:

```
ERROR in main.js
main.js from Terser plugin
unknown field `extractComments`, expected one of `parse`, `compress`, `mangle`, `format`, `output`, `ecma`, ...
```

The babel compiler path sets `extractComments: false` on its
`TerserPlugin`, but the swc path did not.

## Expected Behavior

`compiler: 'swc'` production builds minify successfully, consistent with
the babel path.

## Related Issue(s)

Fixes #36233

## Implementation Details

`terser-webpack-plugin` 5.6 changed its swc minifier to forward the
plugin-level `extractComments` option (default `true`) into
`@swc/core`'s `minify()` options. `@swc/core` rejects `extractComments`
as an unknown field, so any swc production build using Nx's default
minimizer throws. Only `extractComments: false` avoids the forward,
since the plugin skips it only when the value is exactly `false`.

The fix sets `extractComments: false` on the swc `TerserPlugin`,
mirroring the babel branch. Verified against a real webpack build: on
5.6.1 the crash disappears, and the emitted bundle is byte-identical to
the output on the previously pinned 5.3.x (which ignored the option), so
there is no behavior change beyond removing the crash.

The trigger is the `terser-webpack-plugin` 5.6 bump, not a specific
webpack version; the crash reproduces on webpack 5.105.x as well.

<!-- polygraph-session-start -->
---
[View session information
↗](https://app.trypolygraph.com/orgs/6a061dcb561c062131116eca/sessions/gh-36233-863e6541)
<!-- polygraph-session-end -->

(cherry picked from commit 4a63779)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@nx/webpack: swc TerserPlugin missing extractComments: false breaks builds with webpack 5.107+

2 participants