简体   繁体   English

如何在 React App 中启用 Private Method Syntax Proposal?

[英]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 中。

See here for further information.请参阅此处了解更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 @babel/plugin-proposal-private-methods 在 vue.js webpack 模板中工作? - How to make @babel/plugin-proposal-private-methods work in the vue.js webpack template? 如何在Babel 7中启用带有插件提案对象剩余散布的散布运算符? - How do I enable spread operator with plugin-proposal-object-rest-spread in Babel 7? 将 plugin-proposal-class-properties 添加到 create-react-app 项目 - Add plugin-proposal-class-properties to create-react-app project 如何使用 Create React App 和 TypeScript 启用可选链 - How to enable optional chaining with Create React App and TypeScript 如何在 react-native 应用中启用 ES2020? - How to enable ES2020 in react-native app? 如何使用Babel 7的插件提议装饰器和异步函数来装饰异步方法? - How do I decorate an async method using Babel 7's plugin-proposal-decorators with an async function? 从'/ app'找不到模块'@ babel / plugin-proposal-decorators' - Cannot find module '@babel/plugin-proposal-decorators' from '/app' 错误:找不到插件“proposal-private-methods”。 确保 ./available-plugins.js 中有一个条目 - ERROR: Could not find plugin “proposal-private-methods”. Ensure there is an entry in ./available-plugins.js for it 使用 SVG 作为 Private React UI 库中的 React 组件 - (CRA) 在 React 应用程序中使用 Webpack 5 崩溃 - Using SVG as React Component from Private React UI Library-(CRA) inside React app with Webpack 5 crash 尝试使用 babel-plugin-proposal-class-properties 时使用 .babelrc 的语法加倍 - Syntax doubling with .babelrc while trying to use babel-plugin-proposal-class-properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM