Reputation: 17383
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]
Upvotes: 180
Views: 107288
Reputation: 1219
I am using Webpack 5 and I removed below config from my webpack.config. It worked for me after removing. It may help some other people who still facing error
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
Upvotes: 0
Reputation: 2138
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' }
]
}
}
Upvotes: 2
Reputation: 17383
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' }
]
}
};
Upvotes: 404
Reputation: 6385
You should use the migration utility to migrate your webpack config files, it worked for me.
The migration documentation is also useful.
Upvotes: 4
Reputation: 549
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.
Upvotes: 3
Reputation: 161
Use rules
in webpack 4 instead of loaders
.
https://webpack.js.org/concepts/loaders/
Upvotes: 16