简体   繁体   English

@babel/plugin-proposal-class-properties 仍然失败,“classProperties 当前未启用”

[英]@babel/plugin-proposal-class-properties Still Fails with "classProperties isn't currently enabled"

Trying to use @babel/plugin-proposal-class-properties .尝试使用@babel/plugin-proposal-class-properties

A一种

Yields this error产生这个错误

Failed to compile.

./node_modules/react-native-animatable/createAnimatableComponent.js
SyntaxError: /Users/timothyw/Projects/beatthemarket/beatthemarket.reactnative-paper/beatthemarket.frontend/node_modules/react-native-animatable/createAnimatableComponent.js: Support for the experimental syntax 'classProperties' isn't currently enabled (133:24):

  131 |
  132 |   return class AnimatableComponent extends Component {
> 133 |     static displayName = `withAnimatable(${wrappedComponentName})`;
      |                        ^
  134 |
  135 |     static propTypes = {
  136 |       animation: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.

B

Installation and code look like this.安装和代码如下所示。

sh

yarn add @babel/plugin-proposal-class-properties --dev

MyComponent.js我的组件.js

...
<Animatable.View
 animation="pulse"
 easing="ease-out"
 iterationCount="infinite">
 <SocialButton
   onPress={signInWithGoogle}
   imageSource={IMAGES.GOOGLE}
   style={{
     container: themedStyles.googleIconContainer,
     image: themedStyles.googleIcon,
   }}
 />
</Animatable.View>
...

babel.config.js babel.config.js

module.exports = {
  presets: [ "module:metro-react-native-babel-preset", "@babel/preset-env", "@babel/preset-react" ],
  plugins: [ ["@babel/plugin-proposal-class-properties", {"loose": true}] ],
}

C C

And these SO notes don't seem to help.这些 SO 注释似乎没有帮助。

you must install你必须安装

npm install @babel/core @babel/plugin-proposal-class-properties @babel/preset-env @babel/preset-react babel-loader npm install @babel/core @babel/plugin-proposal-class-properties @babel/preset-env @babel/preset-react babel-loader

and

change entry and output更改输入和输出


const path = require('path')        
module.exports = {
  entry: path.resolve(__dirname,'src', 'app.js'),
  output: {
    path: path.resolve(__dirname, "public","dist",'javascript'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.(jsx|js)$/,
        exclude: /node_modules/,
        use: [{
          loader: 'babel-loader',
          options: {
            presets: [
              ['@babel/preset-env', {
                "targets": "defaults"
              }],
              '@babel/preset-react'
            ],
            plugins: [
              "@babel/plugin-proposal-class-properties"
            ]
          }
        }]
      }
    ]
  }
}

in the file webpack.config.js在文件webpack.config.js 中

暂无
暂无

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

相关问题 当前未启用对实验语法“classProperties”的支持 (8:16)。 添加@babel/plugin-proposal-class-properties - Support for the experimental syntax 'classProperties' isn't currently enabled (8:16). Add @babel/plugin-proposal-class-properties @ babel / plugin-proposal-class-properties不起作用 - @babel/plugin-proposal-class-properties doesn't work 错误:找不到模块“@babel/plugin-proposal-class-properties” - Error: Cannot find module '@babel/plugin-proposal-class-properties' 带有 Babel 的 ESLint:在 .eslintrc 中未找到声明的 plugin-proposal-class-properties - ESLint with Babel: plugin-proposal-class-properties not found declared in .eslintrc React - 当前未启用“classProperties” - React - 'classProperties' isn't currently enabled 使用 Jest、Babel、Webpack 和 React 进行测试。 当前未启用对实验性语法“classProperties”的支持 - Testing with Jest, Babel, Webpack, and React. Support for the experimental syntax 'classProperties' isn't currently enabled 尝试在monorepo项目中配置Babel-当前未启用&#39;classProperties&#39;。 如何在monorepo项目中设置Babel? - Trying to configure Babel in a monorepo project - 'classProperties' isn't currently enabled. How to set up Babel in a monorepo project? 当前未启用反应组件模块“classProperties” - react component module 'classProperties' isn't currently enabled Laravel:当前未启用对实验语法“classProperties”的支持 - Laravel: Support for the experimental syntax 'classProperties' isn't currently enabled 如何解决问题当前未启用对实验性语法“classProperties”的支持 - How to solve the problem Support for the experimental syntax 'classProperties' isn't currently enabled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM