个性化阅读
专注于IT技术分析

解决问题:Module build failed ReferenceError [BABEL] main.js Unknown option react.js.Children

使用webpack和babel构建项目时报错,报错信息如下:

Module build failed: ReferenceError: [BABEL] /Users/me/foo/app/main.js: Unknown option: foo/node_modules/react/react.js.Children

Webpack配置如下:

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

module.exports = {
  entry: [
    'babel-polyfill',
    './app/less/main.less',
    './app/main.js',
    'webpack-dev-server/client?http://localhost:8080'
  ],
  output: {
    publicPath: '/',
    filename: 'dist/main.js'
  },
  debug: true,
  devtool: 'source-map',
  module: {
    loaders: [
      {
        test: /\.js$/,
        include: path.join(__dirname, 'app'),

        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015']
        }
      },
      {
        test: /\.less$/,
        loader: "style!css!autoprefixer!less"
      },
    ]
  }
};

解决办法很简单,只需使用npm安装babel-preset-react即可,如下:

npm install babel-preset-react --save-dev
赞(0)
未经允许不得转载:srcmini » 解决问题:Module build failed ReferenceError [BABEL] main.js Unknown option react.js.Children

评论 抢沙发

评论前必须登录!