Skip to content

Commit 557ad05

Browse files
fix: not found module after ask installation (#2761)
1 parent c8fef37 commit 557ad05

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
14
function packageExists(packageName) {
2-
try {
3-
return require.resolve(packageName);
4-
} catch (error) {
5-
return false;
5+
if (process.versions.pnp) {
6+
return true;
67
}
8+
9+
let dir = __dirname;
10+
11+
do {
12+
try {
13+
if (fs.statSync(path.join(dir, "node_modules", packageName)).isDirectory()) {
14+
return true;
15+
}
16+
} catch (_error) {
17+
// Nothing
18+
}
19+
} while (dir !== (dir = path.dirname(dir)));
20+
21+
return false;
722
}
823

924
module.exports = packageExists;

packages/webpack-cli/lib/utils/prompt-installation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function promptInstallation(packageName, preMessage) {
5151
process.exit(2);
5252
}
5353

54-
return utils.packageExists(packageName);
54+
return packageName;
5555
}
5656

5757
process.exit(2);

0 commit comments

Comments
 (0)