From 83d1f58fb52d9dcfa3499efb342dfc47d0cca73a Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 28 Sep 2022 00:11:40 +0530 Subject: [PATCH] fix: respect `NODE_PATH` env variable (#3411) --- packages/webpack-cli/src/webpack-cli.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/webpack-cli/src/webpack-cli.ts b/packages/webpack-cli/src/webpack-cli.ts index db5de4098c9..1f22412b7b7 100644 --- a/packages/webpack-cli/src/webpack-cli.ts +++ b/packages/webpack-cli/src/webpack-cli.ts @@ -156,6 +156,17 @@ class WebpackCLI implements IWebpackCLI { } } while (dir !== (dir = path.dirname(dir))); + // https://github.com/nodejs/node/blob/v18.9.1/lib/internal/modules/cjs/loader.js#L1274 + for (const internalPath of require("module").globalPaths) { + try { + if (fs.statSync(path.join(internalPath, packageName)).isDirectory()) { + return true; + } + } catch (_error) { + // Nothing + } + } + return false; }