From a3ce273a97810ea115e8ab42a1c77d806a0e9776 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Sat, 27 Apr 2019 15:44:27 +0530 Subject: [PATCH] fix(cli): shows error message based on package manager shows different error message based on package manager --- bin/cli.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index e566881ee43..3f0a7503390 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -71,11 +71,18 @@ For more information, see https://webpack.js.org/api/cli/.`); options = require("./utils/convert-argv")(argv); } catch (err) { // 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( - "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n" - ); + if (err.code === "MODULE_NOT_FOUND") { + let errorMessage = + "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n"; + + if (process.env.npm_execpath !== undefined) { + if (process.env.npm_execpath.indexOf("yarn") !== -1) { + errorMessage = + "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33myarn add webpack --dev\n"; + } + } + console.error(errorMessage); return; }