Skip to content

Commit a3ce273

Browse files
committedApr 27, 2019
fix(cli): shows error message based on package manager
shows different error message based on package manager
1 parent cc64955 commit a3ce273

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎bin/cli.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,18 @@ For more information, see https://webpack.js.org/api/cli/.`);
7171
options = require("./utils/convert-argv")(argv);
7272
} catch (err) {
7373
// 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'") {
75-
console.error(
76-
"\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n"
77-
);
74+
if (err.code === "MODULE_NOT_FOUND") {
75+
let errorMessage =
76+
"\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n";
77+
78+
if (process.env.npm_execpath !== undefined) {
79+
if (process.env.npm_execpath.indexOf("yarn") !== -1) {
80+
errorMessage =
81+
"\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33myarn add webpack --dev\n";
82+
}
83+
}
7884

85+
console.error(errorMessage);
7986
return;
8087
}
8188

0 commit comments

Comments
 (0)
Please sign in to comment.