From cc649559f7bd42c4ce00fdeb765f0e356b20f2d8 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Sat, 27 Apr 2019 01:28:31 +0530 Subject: [PATCH] fix(cli): improves error handling with args tells user to install webpack in order for futher procedures --- bin/cli.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index e9a2b5b7410..e566881ee43 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -70,15 +70,19 @@ For more information, see https://webpack.js.org/api/cli/.`); try { options = require("./utils/convert-argv")(argv); } catch (err) { - if (err.name !== "ValidationError") { - console.error("\n\u001b[1m\u001b[31mWebpack not found, please install webpack"); + // When webpack is not installed and no args passed to the CLI + if (err.code === "MODULE_NOT_FOUND" && err.message === "Cannot find module 'webpack-sources'") { console.error( - "\u001b[1m\u001b[31mAlternatively, run 'webpack(-cli) --help' for usage info.\u001b[39m\u001b[22m\n" + "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n" ); - process.exitCode = 1; + return; } + if (err.name !== "ValidationError") { + throw err; + } + const stack = ErrorHelpers.cleanUpWebpackOptions(err.stack, err.message); const message = err.message + "\n" + stack;