@@ -82,7 +82,7 @@ function tryStatSync(path) {
8282 }
8383}
8484
85- function getPackageConfig ( path ) {
85+ function getPackageConfig ( path , specifier , base ) {
8686 const existing = packageJSONCache . get ( path ) ;
8787 if ( existing !== undefined ) {
8888 return existing ;
@@ -106,7 +106,11 @@ function getPackageConfig(path) {
106106 try {
107107 packageJSON = JSONParse ( source ) ;
108108 } catch ( error ) {
109- throw new ERR_INVALID_PACKAGE_CONFIG ( path , null , error . message ) ;
109+ throw new ERR_INVALID_PACKAGE_CONFIG (
110+ path ,
111+ ( base ? `"${ specifier } " from ` : '' ) + fileURLToPath ( base || specifier ) ,
112+ error . message
113+ ) ;
110114 }
111115
112116 let { imports, main, name, type } = packageJSON ;
@@ -130,13 +134,14 @@ function getPackageConfig(path) {
130134 return packageConfig ;
131135}
132136
133- function getPackageScopeConfig ( resolved , base ) {
137+ function getPackageScopeConfig ( resolved ) {
134138 let packageJSONUrl = new URL ( './package.json' , resolved ) ;
135139 while ( true ) {
136140 const packageJSONPath = packageJSONUrl . pathname ;
137141 if ( StringPrototypeEndsWith ( packageJSONPath , 'node_modules/package.json' ) )
138142 break ;
139- const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) , base ) ;
143+ const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) ,
144+ resolved ) ;
140145 if ( packageConfig . exists ) return packageConfig ;
141146
142147 const lastPackageJSONUrl = packageJSONUrl ;
@@ -497,7 +502,7 @@ function packageImportsResolve(name, base, conditions) {
497502 throw new ERR_INVALID_MODULE_SPECIFIER ( name , reason , fileURLToPath ( base ) ) ;
498503 }
499504 let packageJSONUrl ;
500- const packageConfig = getPackageScopeConfig ( base , base ) ;
505+ const packageConfig = getPackageScopeConfig ( base ) ;
501506 if ( packageConfig . exists ) {
502507 packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
503508 const imports = packageConfig . imports ;
@@ -535,7 +540,7 @@ function packageImportsResolve(name, base, conditions) {
535540}
536541
537542function getPackageType ( url ) {
538- const packageConfig = getPackageScopeConfig ( url , url ) ;
543+ const packageConfig = getPackageScopeConfig ( url ) ;
539544 return packageConfig . type ;
540545}
541546
@@ -580,7 +585,7 @@ function packageResolve(specifier, base, conditions) {
580585 StringPrototypeSlice ( specifier , separatorIndex ) ) ;
581586
582587 // ResolveSelf
583- const packageConfig = getPackageScopeConfig ( base , base ) ;
588+ const packageConfig = getPackageScopeConfig ( base ) ;
584589 if ( packageConfig . exists ) {
585590 const packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
586591 if ( packageConfig . name === packageName &&
@@ -608,7 +613,7 @@ function packageResolve(specifier, base, conditions) {
608613 }
609614
610615 // Package match.
611- const packageConfig = getPackageConfig ( packageJSONPath , base ) ;
616+ const packageConfig = getPackageConfig ( packageJSONPath , specifier , base ) ;
612617 if ( packageConfig . exports !== undefined && packageConfig . exports !== null )
613618 return packageExportsResolve (
614619 packageJSONUrl , packageSubpath , packageConfig , base , conditions
0 commit comments