当我在Django项目中设置React时,我遇到了这个错误
模块构建中的ModuleBuildError失败(来自./node_modules/babel-loader/lib/index.js):SyntaxError: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.
Run Code Online (Sandbox Code Playgroud)
所以,我安装了@ 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": "", …Run Code Online (Sandbox Code Playgroud) 我开始写新的使用玩笑和酶反应的应用程序,当尝试使用笑话一样运行测试用例的单元测试用例"test": "jest --watch",而"test": "react-scripts test"测试通过巴贝尔去获得亚军,了解反应的语法。
并且一直在使用 babel 一步一步地进行设置,但是这个错误Support for the experimental syntax 'jsx' isn't currently enabled阻止了我走得更远。正如我在一些线程中所建议的那样,我一直在尝试npm install --save-dev @babel/plugin-transform-react-jsx并尝试将相同的插件添加到 babel 配置中,如下面的 package.json 文件所示,但仍然没有运气。

这是我的 package.json
{
"name": "multitheme-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^3.9.0",
"@material-ui/icons": "^3.0.2",
"axios": "^0.18.0",
"babel-plugin-transform-export-extensions": "^6.22.0",
"jest-css-modules": "^2.1.0",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.5",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts …Run Code Online (Sandbox Code Playgroud)