[英]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. npm start
时出错。 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.我按照这个答案: https://stackoverflow.com/a/55822103/4258041来启用装饰器并且它起作用了,但是我找不到相应customize-cra
组件来以相同的方式添加私有方法语法。 "@babel/plugin-proposal-private-methods": "^7.14.5"
is already installed and saved in my packages.json. "@babel/plugin-proposal-private-methods": "^7.14.5"
已经安装并保存在我的 packages.json 中。
You can use the @babel/plugin-proposal-class-properties.你可以使用 @babel/plugin-proposal-class-properties。 Install with安装
npm install --save-dev @babel/plugin-proposal-class-properties
then add it to your.babelrc plugin section:然后将它添加到 your.babelrc 插件部分:
{
"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.请考虑,在我撰写本文时,这已经是一个过时的答案,因为 Class 字段自 ES2022 以来不再是提案,并且此插件包含在@babel/preset-env 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.