Node.js 模块生成失败:错误:在“中指定了插件0”;“基础”;提供了无效的“财产”;定义;

Node.js 模块生成失败:错误:在“中指定了插件0”;“基础”;提供了无效的“财产”;定义;,node.js,reactjs,webpack,babeljs,Node.js,Reactjs,Webpack,Babeljs,我试图让webpack打包我的react/redux应用程序的生产版本,但未成功。构建通常会成功,但只要我添加一个webpack插件来切换环境,如这里所述:(这在redux记录的警告中链接,因为我正在运行一个小型开发版本),它就会崩溃 webpack.config.js: 'use strict'; var webpack = require('webpack'); var path = require('path'); var BUILD_DIR = path.resolve(__dirn

我试图让webpack打包我的react/redux应用程序的生产版本,但未成功。构建通常会成功,但只要我添加一个webpack插件来切换环境,如这里所述:(这在redux记录的警告中链接,因为我正在运行一个小型开发版本),它就会崩溃

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

有什么想法吗?

我想你把插件定义在了错误的地方。不应在加载程序中定义网页包插件

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;

谢谢您的解决方案导致了另一个错误,但使我走上了正确的轨道。“transform object rest spread”应该保持原样,但是您将DefinePlugin移动到另一个插件数组中是正确的。改变你的答案,我会接受它作为解决办法:)我的错误,我没有认真考虑它编辑解决方案:)