Skip to content

Commit 7f31a49

Browse files
committed
special error message for custom properties in configuration
1 parent 2ea3b59 commit 7f31a49

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

lib/WebpackOptionsValidationError.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,23 @@ WebpackOptionsValidationError.formatValidationError = function formatValidationE
2424
var dataPath = "configuration" + err.dataPath;
2525
switch(err.keyword) {
2626
case "additionalProperties":
27-
return dataPath + " has an unknown property '" + err.params.additionalProperty + "'. These properties are valid:\n" +
27+
var baseMessage = dataPath + " has an unknown property '" + err.params.additionalProperty + "'. These properties are valid:\n" +
2828
getSchemaPartText(err.parentSchema);
29+
if(!err.dataPath) {
30+
return baseMessage + "\n" +
31+
"For typos: please correct them.\n" +
32+
"For loader options: webpack 2 no longer allows custom properties in configuration.\n" +
33+
" Loaders should be updated to allow passing options via loader options in module.rules.\n" +
34+
" Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:\n" +
35+
" plugins: {\n" +
36+
" new webpack.LoaderOptionsPlugin({\n" +
37+
" options: {\n" +
38+
" " + err.params.additionalProperty + ": ...\n" +
39+
" }\n" +
40+
" })\n" +
41+
" }";
42+
}
43+
return baseMessage;
2944
case "oneOf":
3045
case "anyOf":
3146
case "enum":

test/Validation.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ describe("Validation", function() {
8484
" - configuration.module.rules[0].oneOf[0] has an unknown property 'paser'. These properties are valid:",
8585
" object { enforce?, exclude?, include?, issuer?, loader?, loaders?, oneOf?, options?, parser?, query?, resource?, rules?, test?, use? }"
8686
]
87+
}, {
88+
name: "additional key on root",
89+
config: {
90+
entry: "a",
91+
postcss: function() {}
92+
},
93+
message: [
94+
" - configuration has an unknown property 'postcss'. These properties are valid:",
95+
" object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }",
96+
" For typos: please correct them.",
97+
" For loader options: webpack 2 no longer allows custom properties in configuration.",
98+
" Loaders should be updated to allow passing options via loader options in module.rules.",
99+
" Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:",
100+
" plugins: {",
101+
" new webpack.LoaderOptionsPlugin({",
102+
" options: {",
103+
" postcss: ...",
104+
" }",
105+
" })",
106+
" }"
107+
]
87108
}];
88109
testCases.forEach(function(testCase) {
89110
it("should fail validation for " + testCase.name, function() {

0 commit comments

Comments
 (0)