首页 > 解决方案 > React/ASP - 当前未启用对实验性语法“classProperties”的支持

问题描述

一直在关注一篇文章,其中详细介绍了使用 C# 设置React所需的步骤。但是,每次尝试编译 React 应用程序时都会出现以下错误:

Support for the experimental syntax 'classProperties' isn't currently enabled

onChange = (e) => {
    this.setState({ value: parseInt(e.currentTarget.value, 10) });
};

错误消息概述:

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation. If you want to leave it as-is, add @babel/plugin-syntax-class-properties (https://git.io/vb4yQ) to the 'plugins' section to enable parsing.

因此,我改变了我的 package.json 以适应:

{
 "name": "Test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack --config=Scripts/React/config/webpack.config.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.10.3",
    "@babel/plugin-proposal-class-properties": "^7.10.1",
    "@babel/preset-react": "^7.10.1",
    "@babel/preset-env": "^7.2.3",
    "babel-preset-react": "^6.23.0",
    "babel-loader": "^8.1.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.12"
  },
  "dependencies": {
    "react-countup": "^4.3.3",
    "react-router": "^5.2.0",
    "react-svg-gauge": "^1.0.10",
    "reactstrap": "^8.5.1",
    "recharts": "^1.8.5"
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
  }
}

尽管如此,我仍然收到同样的错误。有没有人对我如何缓解这个问题有任何想法?

标签: c#reactjsbabeljs

解决方案


试试这个,可能重复对实验语法 'classProperties' 的支持当前未启用

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

推荐阅读