【问题标题】:React-redux shows error missing class propertises transformReact-redux 显示错误缺少类属性转换
【发布时间】:2019-04-11 23:47:27
【问题描述】:

请 Stackoverflow 伙计们,我知道这个问题已经在这里得到解答,但我无法让它为我工作 handleChange1() 显示 error Missing class properties transform

Error: Missing class properties transform

来自上述来源一些 Stackoverflow 专家建议安装

npm install babel-plugin-transform-class-properties --save-dev

和设置

 "plugins": ["transform-class-properties"]

webpack.config 文件中。我已经做到了,但仍然无法让它工作

import React, { Component } from 'react';
import { render } from 'react-dom';
import Select from 'react-select'
import 'react-select/dist/react-select.css';

class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'React',
      selectedOption: {},

    };
  }

  handleChange1 = (dataSearch) => {
    this.setState({dataSearch});
  }

//代码继续

这里是 webpack.config

var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: './src/index.jsx',
    output: {
        path: path.resolve('dist'),
        filename: 'bundle.js'
    },

module:{
  rules: [
    {
            test: /\.jsx?$/,
            exclude: /(node_modules|bower_components)/,
            loader: 'babel-loader',
            query: {
               presets: ['react', 'es2015', 'stage-3'],
               plugins: ["transform-class-properties"]


            }
        },
    {

      test: /\.(s?)css$/,
      use: [
            "style-loader",
            "css-loader",
            "sass-loader"
          ]
      }]
    },



    resolve: {
        extensions: ['*','.js', '.jsx', '.css', '.scss']
    },


    plugins: [new HtmlWebpackPlugin({
        template: './src/index.html',
        filename: 'index.html',
        inject: 'body'
    })],
    devServer: {
port: 4200,
        historyApiFallback: true

    },
    externals: {
        // global app config object

        config: JSON.stringify({
            apiUrl: 'http://localhost'
        })

    }
}

package.json

{
  "name": "example",
  "version": "1.0.0",
  "repository": {
    "type": "git",
    "url": ""
  },
  "license": "MIT",
  "scripts": {
    "start": "webpack-dev-server --open"
  },
  "dependencies": {
    "history": "^4.6.3",
    "node-sass": "^4.9.4",
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-redux": "^5.0.5",
    "react-router-dom": "^4.1.2",
    "react-select": "^2.1.1",
    "react-toastify": "^4.4.0",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.2.0"
  },
  "devDependencies": {
    "babel-core": "^6.21.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.16.0",
    "babel-preset-stage-3": "^6.24.1",
    "css-loader": "^1.0.1",
    "html-webpack-plugin": "^2.26.0",
    "path": "^0.12.7",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.1",
    "webpack": "^3.6.0",
    "webpack-dev-server": "^2.8.2"
  }
}

【问题讨论】:

    标签: reactjs redux


    【解决方案1】:

    你必须放置

    "plugins": ["transform-class-properties"]
    

    .babelrc 文件中,不在 webpack.config 中。

    应该是这样的:

    .babelrc

    {
      "presets": [...],
      "plugins": [
        [ "transform-class-properties" ]
      ]
    } 
    

    结帐Babel docs on class properties 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 2018-03-08
      • 2017-01-20
      • 2017-06-08
      相关资源
      最近更新 更多