diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js index 92f46ed39713410..ab9842ee53a7c85 100644 --- a/lib/internal/modules/package_json_reader.js +++ b/lib/internal/modules/package_json_reader.js @@ -230,8 +230,7 @@ function parsePackageName(specifier, base) { } function getPackageJSONURL(specifier, base) { - const { packageName, packageSubpath, isScoped } = - parsePackageName(specifier, base); + const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base); // ResolveSelf const packageConfig = getPackageScopeConfig(base); @@ -242,8 +241,7 @@ function getPackageJSONURL(specifier, base) { } } - let packageJSONUrl = - new URL('./node_modules/' + packageName + '/package.json', base); + let packageJSONUrl = new URL(`./node_modules/${packageName}/package.json`, base); let packageJSONPath = fileURLToPath(packageJSONUrl); let lastPath; do { @@ -254,9 +252,10 @@ function getPackageJSONURL(specifier, base) { // Check for !stat.isDirectory() if (stat !== 1) { lastPath = packageJSONPath; - packageJSONUrl = new URL((isScoped ? - '../../../../node_modules/' : '../../../node_modules/') + - packageName + '/package.json', packageJSONUrl); + packageJSONUrl = new URL( + `${isScoped ? '../' : ''}../../../node_modules/${packageName}/package.json`, + packageJSONUrl, + ); packageJSONPath = fileURLToPath(packageJSONUrl); continue; }