Webpack,Karma测试Babel Missing类属性转换

时间:2016-09-14 15:11:56

标签: reactjs webpack karma-runner babeljs

您好我正在React-Redux应用上运行业力测试并收到错误:

Missing class properties transform

即使用

中的静态关键字出错
static propTypes

这只发生在使用karma运行npm测试而不是运行实际应用程序时。 我下载了“babel-plugin-transform-class-properties”:“^ 6.11.5”,并包含在我的webpack.config.js中,如下所示:

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'inline-source-map',
  entry: [
    'babel-polyfill',
    'webpack-hot-middleware/client',
    './src/client/index'
  ],
  output: {
    path: path.resolve(__dirname, './static/dist'),
    filename: 'bundle.js',
    publicPath: '/dist/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
      }
    })
  ],
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        query: {
          plugins: [,
            [
              'react-transform', {
                transforms: [{
                  transform: ['react-transform-hmr',
                  'transform-class-properties']
                  imports: ['react'],
                  locals: ['module']
                }, {
                  transform: 'react-transform-catch-errors',
                  imports: ['react', 'redbox-react']
                }]
              }
            ]
          ]
        },
        include: [path.resolve(__dirname, 'src')]
      },
      {
        test: /\.css?$/,
        loaders: ['style', 'raw']
      }
    ]
  }
};

我的.babelrc文件如下所示:

{
  "presets": ["es2015", "stage-0", "react"]
}

我仍然得到同样的错误。 请让我知道缺少什么,谢谢。 这是我的package.json文件以防万一

"devDependencies": {
    "babel-eslint": "^4.1.2",
    "babel-plugin-react-transform": "^2.0.0",
    "babel-preset-airbnb": "^1.1.1",
    "babel-plugin-transform-class-properties":"^6.11.5",
    "css-loader": "^0.15.1",
    "deep-equal": "^1.0.1",
    "enzyme": "^2.2.0",
    "eslint": "^1.4.3",
    "eslint-config-airbnb": "1.0.0",
    "eslint-plugin-react": "^3.4.0",
    "expect": "^1.10.0",
    "jasmine-core": "^2.4.1",
    "json-loader": "^0.5.4",
    "karma": "^0.13.22",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-chrome-launcher": "^0.2.3",
    "karma-cli": "^1.0.1",
    "karma-coverage": "^0.5.4",
    "karma-jasmine": "^0.3.7",
    "karma-mocha": "^1.1.1",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-spec-reporter": "0.0.24",
    "karma-webpack": "^1.7.0",
    "mocha": "^2.3.2",
    "mocha-jsdom": "^1.0.0",
    "nock": "^2.18.2",
    "phantomjs-prebuilt": "^2.1.4",
    "raw-loader": "^0.5.1",
    "react-addons-test-utils": "^0.14.0",
    "react-hot-loader": "^1.2.7",
    "redux-slider-monitor":"1.0.7",
    "react-transform-catch-errors": "^1.0.0",
    "react-transform-hmr": "^1.0.0",
    "redbox-react": "^1.0.6",
    "redux-devtools": "^3.0.0",
    "redux-devtools-dock-monitor": "^1.0.1",
    "redux-devtools-log-monitor": "^1.0.1",
    "redux-devtools-chart-monitor":"1.4.2",
    "redux-mock-store": "0.0.4",
    "webpack": "^1.9.10",
    "webpack-dev-middleware": "^1.2.0",
    "webpack-dev-server": "^1.9.0",
    "webpack-hot-middleware": "^1.1.0",
    "webpack-isomorphic-tools": "^0.8.8"
  },

0 个答案:

没有答案