gpt4 book ai didi

reactjs - 目前尚未启用对实验性语法 'classProperties' 的支持

转载 作者:行者123 更新时间:2023-12-03 12:53:44 25 4
gpt4 key购买 nike

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

模块构建错误 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js): 语法错误:C:\Users\1Sun\Cebula3\cebula_react\assets\js\index.js:支持 对于实验性语法“classProperties”当前未启用 (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

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"
]
}

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

最佳答案

改变

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

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

这对我有用

关于reactjs - 目前尚未启用对实验性语法 'classProperties' 的支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52237855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com