Skip to content

fix(js): support private methods and static blocks in babel preset - #36218

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

fix(js): support private methods and static blocks in babel preset#36218
leosvelperez merged 1 commit into
masterfrom
gh-36205

Conversation

@leosvelperez

Copy link
Copy Markdown
Member

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


View session information ↗

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.
@netlify

netlify Bot commented Jul 3, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit ac49742
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a47a3847e28c00007398cdd
😎 Deploy Preview https://deploy-preview-36218--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 3, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit ac49742
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a47a384a459d50008b9e952
😎 Deploy Preview https://deploy-preview-36218--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 3, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit ac49742

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 15m 59s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 57s 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-03 14:08:53 UTC

@leosvelperez leosvelperez self-assigned this Jul 3, 2026
@leosvelperez
leosvelperez marked this pull request as ready for review July 3, 2026 14:32
@leosvelperez
leosvelperez requested a review from a team as a code owner July 3, 2026 14:32
@leosvelperez
leosvelperez requested a review from MaxKless July 3, 2026 14:32
@leosvelperez
leosvelperez merged commit 99d542e into master Jul 14, 2026
27 of 28 checks passed
@leosvelperez
leosvelperez deleted the gh-36205 branch July 14, 2026 07:29
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)
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/js/babel preset errors on #private members in transformed ESM deps: missing @babel/plugin-transform-private-methods

2 participants