当前未启用对实验性语法“classProperties"的支持 [英] Support for the experimental syntax 'classProperties' isn't currently enabled

查看:44
本文介绍了当前未启用对实验性语法“classProperties"的支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Django 项目中设置 React 时,我遇到了这个错误

While I was setting up React within Django project I came across this error

ModuleBuildError in模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):语法错误:C:Users1SunCebula3cebula_reactassetsjsindex.js:支持对于实验语法classProperties"当前未启用 (17:9):

ModuleBuildError in Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: C:Users1SunCebula3cebula_reactassetsjsindex.js: Support for the experimental syntax 'classProperties' isn't currently enabled (17:9):

  15 | 
  16 | class BodyPartWrapper extends Component {
> 17 |   state = {
     |         ^
  18 | 
  19 |   }
  20 | 

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

所以,我安装了@babel/plugin-proposal-class-properties 并将其放入 babelrc

So, I installed @babel/plugin-proposal-class-properties and put this in babelrc

package.json

{
  "name": "cebula_react",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --config ./webpack.config.js --mode development",
    "test": "echo "Error: no test specified" && exit 1",
    "build": "webpack --config prod.config.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ]
  },
  "devDependencies": {
    "@babel/cli": "^7.0.0",
    "@babel/core": "^7.0.0",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "react-hot-loader": "^4.3.6",
    "webpack": "^4.17.2",
    "webpack-bundle-tracker": "^0.3.0",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.8"
  },
  "dependencies": {
    "react": "^16.5.0",
    "react-dom": "^16.5.0"
  }
}

babelrc

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

但是错误仍然存​​在,是什么问题??

However the error is still existed, What is the problem??

推荐答案

更改

"plugins": [
    "@babel/plugin-proposal-class-properties"
  ]

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

这对我有用

这篇关于当前未启用对实验性语法“classProperties"的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆