'How to Enable Private Method Syntax Proposal in React App?
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | archetypon |