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; }; };