fix(webpack): disable extractComments on the swc terser minimizer - #36238
Merged
Conversation
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`.
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
View your CI Pipeline Execution ↗ for commit 840ced2
☁️ Nx Cloud last updated this comment at |
jaysoo
approved these changes
Jul 13, 2026
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
Production builds using
@nx/webpack:webpackwithcompiler: 'swc'and optimization enabled crash during minification onceterser-webpack-pluginresolves to 5.6.x:The babel compiler path sets
extractComments: falseon itsTerserPlugin, 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-plugin5.6 changed its swc minifier to forward the plugin-levelextractCommentsoption (defaulttrue) into@swc/core'sminify()options.@swc/corerejectsextractCommentsas an unknown field, so any swc production build using Nx's default minimizer throws. OnlyextractComments: falseavoids the forward, since the plugin skips it only when the value is exactlyfalse.The fix sets
extractComments: falseon the swcTerserPlugin, 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-plugin5.6 bump, not a specific webpack version; the crash reproduces on webpack 5.105.x as well.View session information ↗