Skip to content

Commit 0acd33e

Browse files
Merge pull request #949 from rishabh3112/fix/not-found
fix: module not found error
2 parents 3857b0d + 23eddcb commit 0acd33e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

bin/cli.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@ For more information, see https://webpack.js.org/api/cli/.`);
7171
options = require("./utils/convert-argv")(argv);
7272
} catch (err) {
7373
if (err.code === "MODULE_NOT_FOUND") {
74-
let errorMessage =
75-
"\n\u001b[31mwebpack not installed, consider installing it using \n\u001b[32mnpm install --save-dev webpack\n";
74+
const moduleName = err.message.split("'")[1];
75+
let instructions = "";
76+
let errorMessage = "";
7677

77-
if (process.env.npm_execpath !== undefined && process.env.npm_execpath.includes("yarn")) {
78-
errorMessage =
79-
"\n\u001b[31mwebpack not installed, consider installing it using \n\u001b[32myarn add webpack --dev\n";
80-
}
78+
if (moduleName === "webpack") {
79+
errorMessage = `\n${moduleName} not installed`;
80+
instructions = `Install webpack to start bundling: \u001b[32m\n $ npm install --save-dev ${moduleName}\n`;
8181

82-
console.error(errorMessage);
83-
Error.stackTraceLimit = 1;
84-
process.exitCode = 1;
85-
return;
82+
if (process.env.npm_execpath !== undefined && process.env.npm_execpath.includes("yarn")) {
83+
instructions = `Install webpack to start bundling: \u001b[32m\n $ yarn add ${moduleName} --dev\n`;
84+
}
85+
Error.stackTraceLimit = 1;
86+
console.error(`${errorMessage}\n\n${instructions}`);
87+
process.exitCode = 1;
88+
return;
89+
}
8690
}
8791

8892
if (err.name !== "ValidationError") {

0 commit comments

Comments
 (0)