Skip to content

Commit

Permalink
fix(cli): improves error handling with args
Browse files Browse the repository at this point in the history
tells user to install webpack in order for futher procedures
  • Loading branch information
pranshuchittora committed Apr 26, 2019
1 parent ff263f9 commit cc64955
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bin/cli.js
Expand Up @@ -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;

Expand Down

0 comments on commit cc64955

Please sign in to comment.