Webpack错误: 配置文件中module.rules[0]有一个未知属性'query'。

6

我正在学习这个教程: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']
                }
            }
        ]
    }
}

有人知道我的代码出了什么问题吗?

1个回答

8
错误信息非常明确,rule 配置中没有 query 选项,应该使用 options.presets。请查看Webpack v5用法说明
module: {
  rules: [
    {
      test: /\.m?js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: ['@babel/preset-env']
        }
      }
    }
  ]
}

我已经理解了错误,但是我无法在任何地方找到新的解决方法。谢谢! - Ayo Reis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接