【问题标题】:Support for the experimental syntax 'classProperties' isn't currently enabled (14:13)当前未启用对实验语法“classProperties”的支持 (14:13)
【发布时间】:2020-03-06 09:49:45
【问题描述】:

我一直在使用 react.js,这是第一次发生这种情况,正在开发一个使用 parcel-bundler 设置的应用程序的前端,我在编写简单的 jsx 代码时遇到了这个问题。

Support for the experimental syntax 'classProperties' isn't currently enabled (15:13):
  13 |     }
  14 | 
> 15 |     getCars = () => {
     |            ^
  16 |         console.log('hi')
  17 |     }

我尝试安装 @babel/plugin-proposal-class-properties 并设置一个 .babelrc 文件,正如我在谷歌上搜索错误时看到的那样,但问题相同

{
    "presets": [
        "@babel/preset-react"
    ],
    "plugins": [
        [
            "@babel/plugin-proposal-class-properties",
            {
                "loose": true
            }
        ]
    ]
}

【问题讨论】:

    标签: reactjs jsx babeljs


    【解决方案1】:

    我也有同样的问题。

    package.json

      "devDependencies": {
        "@babel/core": "7.0.0",
        "@babel/plugin-proposal-class-properties": "7.0.0",
        "@babel/plugin-proposal-decorators": "7.0.0"
    ...
      }
    

    .babelrc

    {
      "presets": ["@babel/preset-react", "@babel/preset-env"],
      "plugins": [
        [
          "@babel/plugin-proposal-decorators",
          {
            "legacy": true
          }
        ],
        [
          "@babel/plugin-proposal-class-properties",
          {
            "loose": true
          }
        ]
      ]
    }
    
    

    【讨论】:

    • 是解决方案吗?
    • 仅仅为了包裹工作而添加.babelrc 真的没有意义。这是一个包裹问题,应该由包裹处理,因为他们说这是零配置,所以默认情况下应该可以。我还尝试将 .babelrc 添加到我的项目中,但我不断收到越来越多的错误(因为我使用 React、TypeScript 和其他库)。
    猜你喜欢
    • 2019-02-13
    • 2022-10-22
    • 2021-04-26
    • 2020-08-07
    • 2019-11-10
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 2019-12-12
    相关资源
    最近更新 更多