configuration.module has an unknown property 'loaders'

前端 未结 5 1179
生来不讨喜
生来不讨喜 2020-12-12 17:59

my output of error:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. -

相关标签:
5条回答
  • 2020-12-12 18:09

    You should change loaders to rules in webpack 4:

    change:

    loaders 
    

    to:

    rules
    

    source: Loaders

    Example:

    module.exports = {
      module: {
        rules: [
          { test: /\.css$/, use: 'css-loader' },
          { test: /\.ts$/, use: 'ts-loader' }
        ]
      }
    };
    
    0 讨论(0)
  • 2020-12-12 18:09

    Working for me below webpack.config.js

    module.exports = {
        entry: [
            '.src/index.js'
        ],
        output:{
            path: __dirname,
            filename: 'app/js/main.js'
        },
        module:{
            rules: [
              { test: /\.css$/, use: 'css-loader' },
              { test: /\.ts$/, use: 'ts-loader' }
            ]
        }
    }
    
    0 讨论(0)
  • 2020-12-12 18:15

    Use rules in webpack 4 instead of loaders.

    https://webpack.js.org/concepts/loaders/

    0 讨论(0)
  • 2020-12-12 18:32

    You should use the migration utility to migrate your webpack config files, it worked for me.

    The migration documentation is also useful.

    0 讨论(0)
  • 2020-12-12 18:32

    Above given answers are working but we can resolve this issue by changing webpack and webpack-dev-server version to

    "webpack": "3.8.1",
    "webpack-dev-server": "2.9.4"
    

    It can also solve the issue. Hope it will help.

    0 讨论(0)
提交回复
热议问题