@@ -1074,29 +1074,50 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError);
10741074E ( 'ERR_INVALID_HANDLE_TYPE' , 'This handle type cannot be sent' , TypeError ) ;
10751075E ( 'ERR_INVALID_HTTP_TOKEN' , '%s must be a valid HTTP token ["%s"]' , TypeError ) ;
10761076E ( 'ERR_INVALID_IP_ADDRESS' , 'Invalid IP address: %s' , TypeError ) ;
1077- E ( 'ERR_INVALID_MODULE_SPECIFIER' , ( pkgPath , subpath ) => {
1078- assert ( subpath !== '.' ) ;
1079- return `Package subpath '${ subpath } ' is not a valid module request for the ` +
1080- `"exports" resolution of ${ pkgPath } ${ sep } package.json` ;
1077+ E ( 'ERR_INVALID_MODULE_SPECIFIER' , ( pkgPath , subpath , base = undefined ) => {
1078+ if ( subpath === undefined ) {
1079+ return `Invalid package name '${ pkgPath } ' imported from ${ base } ` ;
1080+ } else if ( base === undefined ) {
1081+ assert ( subpath !== '.' ) ;
1082+ return `Package subpath '${ subpath } ' is not a valid module request for ` +
1083+ `the "exports" resolution of ${ pkgPath } ${ sep } package.json` ;
1084+ } else {
1085+ return `Package subpath '${ subpath } ' is not a valid module request for ` +
1086+ `the "exports" resolution of ${ pkgPath } imported from ${ base } ` ;
1087+ }
10811088} , TypeError ) ;
10821089E ( 'ERR_INVALID_OPT_VALUE' , ( name , value ) =>
10831090 `The value "${ String ( value ) } " is invalid for option "${ name } "` ,
10841091 TypeError ,
10851092 RangeError ) ;
10861093E ( 'ERR_INVALID_OPT_VALUE_ENCODING' ,
10871094 'The value "%s" is invalid for option "encoding"' , TypeError ) ;
1088- E ( 'ERR_INVALID_PACKAGE_CONFIG' ,
1089- `Invalid package config %s${ sep } package.json, %s` , Error ) ;
1090- E ( 'ERR_INVALID_PACKAGE_TARGET' , ( pkgPath , key , subpath , target ) => {
1091- if ( key === '.' ) {
1092- return `Invalid "exports" main target ${ JSONStringify ( target ) } defined ` +
1095+ E ( 'ERR_INVALID_PACKAGE_CONFIG' , ( path , message , hasMessage = true ) => {
1096+ if ( hasMessage )
1097+ return `Invalid package config ${ path } ${ sep } package.json, ${ message } ` ;
1098+ else
1099+ return `Invalid JSON in ${ path } imported from ${ message } ` ;
1100+ } , Error ) ;
1101+ E ( 'ERR_INVALID_PACKAGE_TARGET' ,
1102+ ( pkgPath , key , subpath , target , base = undefined ) => {
1103+ if ( key === null ) {
1104+ if ( subpath !== '' ) {
1105+ return `Invalid "exports" target ${ JSONStringify ( target ) } defined ` +
1106+ `for '${ subpath } ' in the package config ${ pkgPath } imported from ` +
1107+ base ;
1108+ } else {
1109+ return `Invalid "exports" main target ${ target } defined in the ` +
1110+ `package config ${ pkgPath } imported from ${ base } .` ;
1111+ }
1112+ } else if ( key === '.' ) {
1113+ return `Invalid "exports" main target ${ JSONStringify ( target ) } defined ` +
10931114 `in the package config ${ pkgPath } ${ sep } package.json` ;
1094- } else {
1095- return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
1096- StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
1115+ } else {
1116+ return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
1117+ StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
10971118 `package config ${ pkgPath } ${ sep } package.json` ;
1098- }
1099- } , Error ) ;
1119+ }
1120+ } , Error ) ;
11001121E ( 'ERR_INVALID_PERFORMANCE_MARK' ,
11011122 'The "%s" performance mark has not been set' , Error ) ;
11021123E ( 'ERR_INVALID_PROTOCOL' ,
@@ -1207,6 +1228,9 @@ E('ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK',
12071228 'The ES Module loader may not return a format of \'dynamic\' when no ' +
12081229 'dynamicInstantiate function was provided' , Error ) ;
12091230E ( 'ERR_MISSING_OPTION' , '%s is required' , TypeError ) ;
1231+ E ( 'ERR_MODULE_NOT_FOUND' , ( path , base , type = 'package' ) => {
1232+ return `Cannot find ${ type } '${ path } ' imported from ${ base } ` ;
1233+ } , Error ) ;
12101234E ( 'ERR_MULTIPLE_CALLBACK' , 'Callback called multiple times' , Error ) ;
12111235E ( 'ERR_NAPI_CONS_FUNCTION' , 'Constructor must be a function' , TypeError ) ;
12121236E ( 'ERR_NAPI_INVALID_DATAVIEW_ARGS' ,
@@ -1241,12 +1265,15 @@ E('ERR_OUT_OF_RANGE',
12411265 msg += ` It must be ${ range } . Received ${ received } ` ;
12421266 return msg ;
12431267 } , RangeError ) ;
1244- E ( 'ERR_PACKAGE_PATH_NOT_EXPORTED' , ( pkgPath , subpath ) => {
1268+ E ( 'ERR_PACKAGE_PATH_NOT_EXPORTED' , ( pkgPath , subpath , base = undefined ) => {
12451269 if ( subpath === '.' ) {
12461270 return `No "exports" main resolved in ${ pkgPath } ${ sep } package.json` ;
1247- } else {
1271+ } else if ( base === undefined ) {
12481272 return `Package subpath '${ subpath } ' is not defined by "exports" in ${
12491273 pkgPath } ${ sep } package.json`;
1274+ } else {
1275+ return `Package subpath '${ subpath } ' is not defined by "exports" in ${
1276+ pkgPath } imported from ${ base } `;
12501277 }
12511278} , Error ) ;
12521279E ( 'ERR_REQUIRE_ESM' ,
0 commit comments