Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configuration.module has an unknown property 'loaders'

my output of error:

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).

my webpack.config.js:

var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');

var config = {
  entry: APP_DIR + '/index.jsx',
  module : {
    loaders : [
      {
        test : /\.jsx?/,
        include : APP_DIR,
        loader : 'babel-loader'
      }
    ]
  },
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  }

};


module.exports = config;

my webpack version:

[email protected]
like image 985
S.M_Emamian Avatar asked Oct 08 '22 16:10

S.M_Emamian


2 Answers

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' }
    ]
  }
};
like image 145
S.M_Emamian Avatar answered Oct 11 '22 07:10

S.M_Emamian


Use rules in webpack 4 instead of loaders.

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

like image 34
Shawn Stephens Avatar answered Oct 11 '22 05:10

Shawn Stephens