4

I got "Class private methods are not enabled." error when running npm start on a project using leading # to indicate private methods. I followed this answer: https://stackoverflow.com/a/55822103/4258041 to enable the decorator and it worked, but I cannot find corresponding customize-cra components to add private method syntax in a same way. "@babel/plugin-proposal-private-methods": "^7.14.5" is already installed and saved in my packages.json.

Yan Yang
  • 1,804
  • 2
  • 15
  • 37

1 Answers1

5

You can use the @babel/plugin-proposal-class-properties. Install with

npm install --save-dev @babel/plugin-proposal-class-properties

then add it to your .babelrc plugin section:

{
  "plugins": ["@babel/plugin-proposal-class-properties"]
}

Please consider that while I'm writing this is already an outdated answer, since Class Fields are no longer a proposal since ES2022 and this plugin is included in @babel/preset-env.

See here for further information.

archetypon
  • 61
  • 1
  • 5