Skip to content

Commit cc64955

Browse files
committedApr 26, 2019
fix(cli): improves error handling with args
tells user to install webpack in order for futher procedures
1 parent ff263f9 commit cc64955

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
 

‎bin/cli.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,19 @@ For more information, see https://webpack.js.org/api/cli/.`);
7070
try {
7171
options = require("./utils/convert-argv")(argv);
7272
} catch (err) {
73-
if (err.name !== "ValidationError") {
74-
console.error("\n\u001b[1m\u001b[31mWebpack not found, please install webpack");
73+
// When webpack is not installed and no args passed to the CLI
74+
if (err.code === "MODULE_NOT_FOUND" && err.message === "Cannot find module 'webpack-sources'") {
7575
console.error(
76-
"\u001b[1m\u001b[31mAlternatively, run 'webpack(-cli) --help' for usage info.\u001b[39m\u001b[22m\n"
76+
"\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n"
7777
);
78-
process.exitCode = 1;
78+
7979
return;
8080
}
8181

82+
if (err.name !== "ValidationError") {
83+
throw err;
84+
}
85+
8286
const stack = ErrorHelpers.cleanUpWebpackOptions(err.stack, err.message);
8387
const message = err.message + "\n" + stack;
8488

0 commit comments

Comments
 (0)
Please sign in to comment.