为jsx文件{j}提交js webpack绑定错误

时间:2016-09-07 18:21:27

标签: reactjs webpack jsx

我目前正在做一个小应用程序。我使用Webpack捆绑我的文件,当我尝试在命令行中执行webpack时,我在下面收到此错误,但是,如果条目扩展名为' ./ public / app.js'它完美地运作。我不明白我做错了什么。我确实看过其他一些帖子,但与我的问题不同。如果有任何感谢,我将不胜感激。

./public/app.jsx中的错误 模块构建失败:ReferenceError:[BABEL] /Users/jair/Desktop/development/react-test/public/app.jsx:未知选项:base.preset。查看http://babeljs.io/docs/usage/options/了解详情     在Logger.error(/Users/jair/Desktop/development/react-test/node_modules/babel-core/lib/transformation/file/logger.js:41:11)     在OptionManager.mergeOptions(/Users/jair/Desktop/development/react-test/node_modules/babel-core/lib/transformation/file/options/option-manager.js:216:20)     在OptionManager.init(/Users/jair/Desktop/development/react-test/node_modules/babel-core/lib/transformation/file/options/option-manager.js:338:12)     在File.initOptions(/Users/jair/Desktop/development/react-test/node_modules/babel-core/lib/transformation/file/index.js:216:65)     在新文件(/Users/jair/Desktop/development/react-test/node_modules/babel-core/lib/transformation/file/index.js:137:24)     在Pipeline.transform(/Users/jair/Desktop/development/react-test/node_modules/babel-core/lib/transformation/pipeline.js:46:16)     在transpile(/Users/jair/Desktop/development/react-test/node_modules/babel-loader/index.js:38:20)     at Object.module.exports(/Users/jair/Desktop/development/react-test/node_modules/babel-loader/index.js:131:12)

module.exports = {
entry: './public/app.jsx',
output: {
  path: __dirname,
  filename: './public/bundle.js'
},
resolve: {
  exensions: ['', '.js', '.jsx']
},
module: {
  loaders: [
    {
       loader: 'babel-loader',
       query: {
         preset: ['react', 'es2015']
       },
       test: /\.jsx?$/,
       exclude: /(node_modules | bower_components)/
    }
  ]
}

};

1 个答案:

答案 0 :(得分:2)

正确的选项名称为presets,而不是preset

query: {
  presets: ['react', 'es2015']
}

另外,我认为exclude正则表达式中的空格需要删除:

exclude: /(node_modules|bower_components)/

希望这有帮助!