About the configuration of loaders in webpack configuration files for beginners

self-taught to use the configuration file from a tutorial of webpack,copy a year ago, but it seems that the new version does not support the old writing. My configuration file is as follows:

module.exports = {
  entry: "./app.js",
  output: {
    filename: "bundle.js"
  },
  module: {
    loaders:[
      {
        test: /\.js[x]?$/,
        exclude: /node_modules/,
        loader: "babel-loader?presets[]=es2015&presets[]=react"
      },
    ]
  }
}

the error message is as follows:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property "loaders". These properties are valid:
   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
   -> Options affecting the normal modules (`NormalModuleFactory`).

ask for expert advice

Mar.02,2021

look at your loader. You want to use webpack with react. There is an options missing under your loaders.
gives you a reference (rules can also be changed to loaders):

const path =require('path');   
module.exports = {  
  entry: path.resolve(__dirname, 'index.js'),  
  output: {  
    path: path.resolve(__dirname, ''),  
    filename: "bundle.js"  
  },  
  mode: 'development',
  module: {  
    rules: [  
      {  
        test:  /\.js$/,   
        exclude: /node_modules/,  
        loader: "babel-loader",  
        options: {  
          presets: ["es2015","react"]   
        }  
      }  
    ]  
  }  
}; 
For specific configuration, you can also refer to the article I wrote earlier: https://codeshelper.com/a/11.

.
Menu