fix(js): support private methods and static blocks in babel preset - #36218
Merged
Conversation
The @nx/js/babel preset loads @babel/plugin-transform-class-properties on its own, which runs babel's shared class-features plugin. That plugin hard-errors on #private methods and static blocks unless their companion transforms are loaded too, so babel-jest failed with "Class private methods are not enabled" when transforming an ESM-only dependency that uses such syntax (un-ignored via transformIgnorePatterns). Load the companion class-features transforms next to class-properties: private-methods and private-property-in-object with the same loose setting (babel requires loose to match across the three), plus class-static-block. This clears the whole family of "not enabled" hard-errors, not just private methods.
✅ 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 ac49742
☁️ 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
…36218) ## Current Behavior The `@nx/js/babel` preset loads `@babel/plugin-transform-class-properties` on its own. That plugin runs babel's shared class-features transform, which hard-errors on `#private` methods and `static {}` blocks unless their companion transforms are also loaded. When babel-jest transforms an ESM-only dependency that uses this syntax (un-ignored through `transformIgnorePatterns`, the documented way to consume ESM-only packages), the transform fails: ``` SyntaxError: Class private methods are not enabled. Please add `@babel/plugin-transform-private-methods` to your configuration. ``` ## Expected Behavior The preset transforms private methods, `#private in obj` checks, and static blocks instead of erroring. It now loads the companion class-features transforms next to `class-properties`: `private-methods` and `private-property-in-object` with the same `loose` setting (babel requires `loose` to match across the three), plus `class-static-block`. This clears the whole family of "not enabled" hard-errors, not just private methods. A regression test covering the affected syntax is added. ## Related Issue(s) Fixes #36205 <!-- polygraph-session-start --> --- [View session information ↗](https://app.trypolygraph.com/orgs/6a061dcb561c062131116eca/sessions/gh-36205-21561609) <!-- polygraph-session-end --> (cherry picked from commit 99d542e)
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
The
@nx/js/babelpreset loads@babel/plugin-transform-class-propertieson its own. That plugin runs babel's shared class-features transform, which hard-errors on#privatemethods andstatic {}blocks unless their companion transforms are also loaded. When babel-jest transforms an ESM-only dependency that uses this syntax (un-ignored throughtransformIgnorePatterns, the documented way to consume ESM-only packages), the transform fails:Expected Behavior
The preset transforms private methods,
#private in objchecks, and static blocks instead of erroring. It now loads the companion class-features transforms next toclass-properties:private-methodsandprivate-property-in-objectwith the sameloosesetting (babel requireslooseto match across the three), plusclass-static-block. This clears the whole family of "not enabled" hard-errors, not just private methods. A regression test covering the affected syntax is added.Related Issue(s)
Fixes #36205
View session information ↗