@@ -77,7 +77,7 @@ function tryStatSync(path) {
7777 }
7878}
7979
80- function getPackageConfig ( path ) {
80+ function getPackageConfig ( path , specifier , base ) {
8181 const existing = packageJSONCache . get ( path ) ;
8282 if ( existing !== undefined ) {
8383 return existing ;
@@ -101,7 +101,11 @@ function getPackageConfig(path) {
101101 try {
102102 packageJSON = JSONParse ( source ) ;
103103 } catch ( error ) {
104- throw new ERR_INVALID_PACKAGE_CONFIG ( path , null , error . message ) ;
104+ throw new ERR_INVALID_PACKAGE_CONFIG (
105+ path ,
106+ ( base ? `"${ specifier } " from ` : '' ) + fileURLToPath ( base || specifier ) ,
107+ error . message
108+ ) ;
105109 }
106110
107111 let { imports, main, name, type } = packageJSON ;
@@ -125,13 +129,14 @@ function getPackageConfig(path) {
125129 return packageConfig ;
126130}
127131
128- function getPackageScopeConfig ( resolved , base ) {
132+ function getPackageScopeConfig ( resolved ) {
129133 let packageJSONUrl = new URL ( './package.json' , resolved ) ;
130134 while ( true ) {
131135 const packageJSONPath = packageJSONUrl . pathname ;
132136 if ( StringPrototypeEndsWith ( packageJSONPath , 'node_modules/package.json' ) )
133137 break ;
134- const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) , base ) ;
138+ const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) ,
139+ resolved ) ;
135140 if ( packageConfig . exists ) return packageConfig ;
136141
137142 const lastPackageJSONUrl = packageJSONUrl ;
@@ -492,7 +497,7 @@ function packageImportsResolve(name, base, conditions) {
492497 throw new ERR_INVALID_MODULE_SPECIFIER ( name , reason , fileURLToPath ( base ) ) ;
493498 }
494499 let packageJSONUrl ;
495- const packageConfig = getPackageScopeConfig ( base , base ) ;
500+ const packageConfig = getPackageScopeConfig ( base ) ;
496501 if ( packageConfig . exists ) {
497502 packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
498503 const imports = packageConfig . imports ;
@@ -530,7 +535,7 @@ function packageImportsResolve(name, base, conditions) {
530535}
531536
532537function getPackageType ( url ) {
533- const packageConfig = getPackageScopeConfig ( url , url ) ;
538+ const packageConfig = getPackageScopeConfig ( url ) ;
534539 return packageConfig . type ;
535540}
536541
@@ -575,7 +580,7 @@ function packageResolve(specifier, base, conditions) {
575580 StringPrototypeSlice ( specifier , separatorIndex ) ) ;
576581
577582 // ResolveSelf
578- const packageConfig = getPackageScopeConfig ( base , base ) ;
583+ const packageConfig = getPackageScopeConfig ( base ) ;
579584 if ( packageConfig . exists ) {
580585 const packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
581586 if ( packageConfig . name === packageName &&
@@ -603,7 +608,7 @@ function packageResolve(specifier, base, conditions) {
603608 }
604609
605610 // Package match.
606- const packageConfig = getPackageConfig ( packageJSONPath , base ) ;
611+ const packageConfig = getPackageConfig ( packageJSONPath , specifier , base ) ;
607612 if ( packageConfig . exports !== undefined && packageConfig . exports !== null )
608613 return packageExportsResolve (
609614 packageJSONUrl , packageSubpath , packageConfig , base , conditions
0 commit comments