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

环境

React 16.13

出错信息:
Support for the experimental syntax ‘classProperties‘ isn‘t currently enabled_第1张图片出错的原因:

Support for the experimental syntax ‘classProperties’ isn’t currently enabled
解决方式 一:
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

解决

采用方案一:

npm install --save-dev @babel/plugin-proposal-class-properties

修改 webpack的配置文件(我的是webpack.config.js)
babel-loader的配置下新增plugins配置项:

{
     
    test: /\.(js|jsx)$/,
    exclude: /(node_modules|bower_components)/,
    use: {
     
        loader: 'babel-loader',
        options: {
     
            presets: [
                '@babel/preset-env', 
                '@babel/preset-react',
            ],
            plugins: [
                "@babel/plugin-proposal-class-properties",
            ]
        }
    }
},

babel-loader 详细配置项见: https://www.webpackjs.com/loaders/babel-loader/

webpack配置文件修改后,重启应用即可。

你可能感兴趣的:(配置,webpack,babel,ES6)