【问题标题】:Webpack error: configuration.module.rules[0] has an unknown property 'query'Webpack 错误:configuration.module.rules[0] 有一个未知属性 'query'
【发布时间】:2021-10-29 05:15:21
【问题描述】:

我正在关注本教程:https://www.youtube.com/watch?v=iWUR04B42Hc,我知道它的内容已过时,但我认为已将其正确翻译成 Webpack 的较新版本,但出现此错误:configuration.module.rules[0] has an unknown property 'query'.

完全错误:

[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 { assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }
   -> A rule description with conditions and effects for modules.

我的 webpack.config.js

const path = require('path');

module.exports = {
    entry: {
        app: './source/app.js'
    },
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: 'app.bundle.js'
    },
    mode: 'development',
    module: {
        rules: [
            {
                test: /\.js?$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['@babel/preset-env']
                }
            }
        ]
    }
}

你知道我的代码有什么问题吗?

【问题讨论】:

    标签: javascript webpack ecmascript-6 babeljs ecmascript-5


    【解决方案1】:

    错误信息很清楚,rule配置上没有query选项,你应该使用options.presetsWebpack v5

    usage
    module: {
      rules: [
        {
          test: /\.m?js$/,
          exclude: /(node_modules|bower_components)/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env']
            }
          }
        }
      ]
    }
    

    【讨论】:

    • 我已经理解了这个错误,但我还是找不到新的方法。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2021-01-29
    • 2018-03-12
    • 2017-04-16
    • 2018-08-18
    • 2018-09-29
    • 2017-07-17
    • 1970-01-01
    • 2012-09-08
    相关资源
    最近更新 更多