diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index c3c0758cf8ab47..eba9a54641b34c 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -49,7 +49,6 @@ const { SafeSet, String, StringPrototypeIndexOf, - StringPrototypeLastIndexOf, StringPrototypeMatch, StringPrototypeSlice, StringPrototypeStartsWith, @@ -310,13 +309,12 @@ function readPackageScope(checkPath) { const rootSeparatorIndex = checkPath.indexOf(path.sep); let separatorIndex; while ( - (separatorIndex = StringPrototypeLastIndexOf(checkPath, path.sep)) >= - rootSeparatorIndex + (separatorIndex = checkPath.lastIndexOf(path.sep)) > rootSeparatorIndex ) { checkPath = checkPath.slice(0, separatorIndex); if (checkPath.endsWith(path.sep + 'node_modules')) return false; - const pjson = readPackage(checkPath + path.sep); + const pjson = readPackage(checkPath); if (pjson) return { path: checkPath, data: pjson