question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I enable private methods?

See original GitHub issue

I’m surprised they aren’t enabled by default? because ember-cli-babel has them 🙃

but anywho, I have this error in C.I.: https://github.com/NullVoxPopuli/ember-array-map-resource/pull/103/checks?check_run_id=3702630696#step:5:215

 - originalErrorMessage: /home/runner/work/ember-array-map-resource/ember-array-map-resource/-private/resources/array-map.ts: Class private methods are not enabled.
  20 |
  21 |   // @private
> 22 |   get #records(): Element[] {
     |   ^
  23 |     return this.args.positional[0];
  24 |   }
  25 |
  - stack: SyntaxError: /home/runner/work/ember-array-map-resource/ember-array-map-resource/-private/resources/array-map.ts: Class private methods are not enabled.

Classic build works just fine with private fields: https://github.com/NullVoxPopuli/ember-array-map-resource/pull/103/checks?check_run_id=3702630588

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rwjbluecommented, Nov 17, 2021

I believe this is the same thing I described in https://github.com/babel/ember-cli-babel/issues/419#issuecomment-971787156, since we use ember-cli-babel for compilation still we’re going to have the same issue.

1reaction
courajscommented, Nov 16, 2021

Been running into this as well. Discovered @embroider/webpack depends on the old pre-release version of babel’s preset env. babel-preset-env has been deprecated in favor of @babel/preset-env. Looks like the new versions use plugin-proposal-private-methods: https://github.com/babel/babel/blob/87fc2e76d77b0bc78b76cced469bd64c5edf141f/packages/babel-preset-env/package.json#L37 But the pre-release package doesn’t: https://github.com/babel/babel-preset-env/blob/31f33e3656e1bd8036317c54128fdc2812a2e8aa/package.json#L24

So I believe the solution is to migrate from babel-preset-env to @babel/preset-env

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/plugin-proposal-private-methods
When true, private methods will be assigned directly on its parent via Object.defineProperty rather than a WeakSet . This results in improved performance ......
Read more >
Private class features - JavaScript - MDN Web Docs - Mozilla
Class fields are public by default, but private class members can be created by using a hash # prefix. The privacy encapsulation of...
Read more >
How to Enable Private Method Syntax Proposal in React App?
You can use the @babel/plugin-proposal-class-properties. Install with npm install --save-dev @babel/plugin-proposal-class-properties.
Read more >
Class private methods are not enabled. #419 - GitHub
When I run ember s I see the error described Class private methods are not enabled . Do we just need to wait...
Read more >
Babel 7.14 enables class fields & private methods by default ...
Babel 7.14 enables class fields & private methods by default in @babel/preset-env ... Babel is a free and open-source JavaScript transcompiler. It ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found