首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@babel/plugin-提案类-属性仍然会失败,因为"classProperties当前未启用“

@babel/plugin-提案类-属性仍然会失败,因为"classProperties当前未启用“
EN

Stack Overflow用户
提问于 2020-10-29 16:58:50
回答 1查看 431关注 0票数 2

尝试使用@babel/plugin-proposal-class-properties

一个

产生此错误

代码语言:javascript
复制
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

安装和代码如下所示。

sh

代码语言:javascript
复制
yarn add @babel/plugin-proposal-class-properties --dev

MyComponent.js

代码语言:javascript
复制
...
<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

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

C

这些笔记似乎没什么用。

EN

回答 1

Stack Overflow用户

发布于 2021-02-21 10:47:49

您必须安装

npm安装@babel/core @babel/plugin-提议-class-properties@babel/预设-env@babel/预设-react-加载器

更改输入和输出

代码语言:javascript
复制
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"
            ]
          }
        }]
      }
    ]
  }
}

在文件webpack.config.js

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64595800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档