首页 > 解决方案 > Webpack-CLI 错误:配置对象无效

问题描述

我在互联网上搜索了这个问题的答案,但找不到能回答我遇到的具体问题的答案。我创建了一个 webpack.config.js,当我尝试使用 webpack-cli 运行它时,我收到以下错误消息

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[0] has an unknown property 'query'. These properties are valid:
   object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }
   -> A rule description with conditions and effects for modules.

这是我的 webpack.config.js 文件

// Load the needed node modules
var path = require("path");
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');

// Webpack project settings
module.exports = {
    context: __dirname,
    entry: {
        lobby: './templates/components/lobby/index',
    },
    output: {
        path: path.resolve('./static/bundles/'),
        filename: "[name]-[hash].js"
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(), // don't reload if there is an error
        new BundleTracker({path: __dirname, filename: './webpack-stats.json'})
    ],
    module: {
        rules: [
            {
                test: /\.jsx$/,
                exclude: /(node_modules)/,
                loader: 'babel-loader', // 'babel-loader' is also a legal name to reference
                query: {
                    presets: ['es2015', 'react']
                }
            },
        ]
    },

    resolve: {
        modules: ['node_modules'],
        extensions: ['.jsx', '.js']
    }
}

我对 Webpack 不是很熟练,但是我遵循了一些关于它的教程,我认为它看起来应该如何设置 webpack 文件,所以我不知道为什么会出现这个错误。

标签: javascriptwebpack

解决方案


推荐阅读