模块构build失败:错误:在“base”中指定的插件0提供了“definitions”的无效属性

我没有成功地试图让webpack打包我的react / redux应用程序的生产版本。 构build成功正常,但只要我添加一个webpack插件切换环境详细在这里: https ://stackoverflow.com/a/30061249/7114096(这是链接在由我正在运行缩小的开发版本),它跌倒了。

webpack.config.js:

'use strict'; var webpack = require('webpack'); var path = require('path'); var BUILD_DIR = path.resolve(__dirname, 'web/bundles/frontend/build/react'); var APP_DIR = path.resolve(__dirname, 'web/bundles/frontend/src/react'); var config = { entry: ['babel-polyfill', APP_DIR + '/search.js'], output: { path: BUILD_DIR, filename: 'search.js' }, module : { loaders : [ { test : /\.js?/, include : APP_DIR, loader : 'babel', query: { presets: ['react','es2015'], plugins: [ new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('development') } }), "transform-object-rest-spread" ] } } ] } }; module.exports = config; 

的package.json:

 "babel-cli": "^6.16.0", "babel-core": "^6.18.2", "babel-loader": "^6.2.5", "babel-plugin-transform-object-rest-spread": "^6.16.0", "babel-polyfill": "^6.16.0", "babel-preset-es2015": "^6.16.0", "babel-preset-node5": "^11.1.0", "babel-preset-react": "^6.16.0", "bower": "^1.7.9", "bower-update-all": "^0.1.2", "csswring": "^5.1.0", "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.0", "gulp-babel": "^6.1.2", "gulp-browserify": "^0.5.1", "gulp-clean-css": "^2.0.11", "gulp-compass": "^2.1.0", "gulp-concat": "^2.6.0", "gulp-imagemin": "^3.0.2", "gulp-minify": "0.0.12", "gulp-plumber": "^1.1.0", "gulp-postcss": "^6.1.1", "gulp-rename": "^1.2.2", "gulp-sourcemaps": "^1.6.0", "gulp-util": "^3.0.7", "gulp-webpack": "^1.5.0", "merge-stream": "^1.0.0", "path": "^0.12.7", "postcss-cssnext": "^2.7.0", "react": "^15.3.2", "react-bootstrap": "^0.30.5", "react-dom": "^15.3.2", "react-redux": "^4.4.5", "redux": "^3.6.0", "redux-saga": "^0.12.0", "require-dir": "^0.3.0", "webpack": "^1.13.3" 

最后错误:

 ERROR in ./web/bundles/frontend/src/react/search.js Module build failed: Error: Plugin 0 specified in "base" provided an invalid property of "definitions" at Plugin.init (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\plugin.js:131:13) at Function.normalisePlugin (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:148:12) at C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:180:30 at Array.map (native) at Function.normalisePlugins (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:154:20) at OptionManager.mergeOptions (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:229:36) at OptionManager.init (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\file\options\option-manager.js:374:12) at File.initOptions (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\file\index.js:216:65) at new File (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\file\index.js:139:24) at Pipeline.transform (C:\xampp\htdocs\test\node_modules\babel-core\lib\transformation\pipeline.js:46:16) at transpile (C:\xampp\htdocs\test\node_modules\babel-loader\index.js:38:20) at Object.module.exports (C:\xampp\htdocs\test\node_modules\babel-loader\index.js:131:12) @ multi main 

有什么想法吗?

       

网上收集的解决方案 "模块构build失败:错误:在“base”中指定的插件0提供了“definitions”的无效属性"

我想你有你的插件定义在错误的地方。 Webpack插件不应该在加载器中定义

 var webpack = require('webpack'); var path = require('path'); var BUILD_DIR = path.resolve(__dirname, 'web/bundles/frontend/build/react'); var APP_DIR = path.resolve(__dirname, 'web/bundles/frontend/src/react'); var config = { entry: ['babel-polyfill', APP_DIR + '/search.js'], output: { path: BUILD_DIR, filename: 'search.js' }, module : { loaders : [ { test : /\.js?/, include : APP_DIR, loader : 'babel', query: { presets: ['react','es2015'], plugins: ["transform-object-rest-spread"] } } ] }, plugins: [ new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('development') } }) ] }; module.exports = config;