From c90f36e95b2447e2e0af50ecd4e90358258b15c1 Mon Sep 17 00:00:00 2001 From: Mark Zuber Date: Mon, 7 Nov 2022 01:07:28 -0800 Subject: [PATCH] Update bootstrap-node.js to check for Array.isArray (#165289) * Update bootstrap-node.js to check for Array.isArray * Update --- src/bootstrap-node.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bootstrap-node.js b/src/bootstrap-node.js index 47f3443873c..914b8290380 100644 --- a/src/bootstrap-node.js +++ b/src/bootstrap-node.js @@ -78,11 +78,14 @@ exports.removeGlobalNodeModuleLookupPaths = function () { // @ts-ignore Module._resolveLookupPaths = function (moduleName, parent) { const paths = originalResolveLookupPaths(moduleName, parent); - let commonSuffixLength = 0; - while (commonSuffixLength < paths.length && paths[paths.length - 1 - commonSuffixLength] === globalPaths[globalPaths.length - 1 - commonSuffixLength]) { - commonSuffixLength++; + if (Array.isArray(paths)) { + let commonSuffixLength = 0; + while (commonSuffixLength < paths.length && paths[paths.length - 1 - commonSuffixLength] === globalPaths[globalPaths.length - 1 - commonSuffixLength]) { + commonSuffixLength++; + } + return paths.slice(0, paths.length - commonSuffixLength); } - return paths.slice(0, paths.length - commonSuffixLength); + return paths; }; };