@@ -1078,29 +1078,50 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError);
10781078E ( 'ERR_INVALID_HANDLE_TYPE' , 'This handle type cannot be sent' , TypeError ) ;
10791079E ( 'ERR_INVALID_HTTP_TOKEN' , '%s must be a valid HTTP token ["%s"]' , TypeError ) ;
10801080E ( 'ERR_INVALID_IP_ADDRESS' , 'Invalid IP address: %s' , TypeError ) ;
1081- E ( 'ERR_INVALID_MODULE_SPECIFIER' , ( pkgPath , subpath ) => {
1082- assert ( subpath !== '.' ) ;
1083- return `Package subpath '${ subpath } ' is not a valid module request for the ` +
1084- `"exports" resolution of ${ pkgPath } ${ sep } package.json` ;
1081+ E ( 'ERR_INVALID_MODULE_SPECIFIER' , ( pkgPath , subpath , base = undefined ) => {
1082+ if ( subpath === undefined ) {
1083+ return `Invalid package name '${ pkgPath } ' imported from ${ base } ` ;
1084+ } else if ( base === undefined ) {
1085+ assert ( subpath !== '.' ) ;
1086+ return `Package subpath '${ subpath } ' is not a valid module request for ` +
1087+ `the "exports" resolution of ${ pkgPath } ${ sep } package.json` ;
1088+ } else {
1089+ return `Package subpath '${ subpath } ' is not a valid module request for ` +
1090+ `the "exports" resolution of ${ pkgPath } imported from ${ base } ` ;
1091+ }
10851092} , TypeError ) ;
10861093E ( 'ERR_INVALID_OPT_VALUE' , ( name , value ) =>
10871094 `The value "${ String ( value ) } " is invalid for option "${ name } "` ,
10881095 TypeError ,
10891096 RangeError ) ;
10901097E ( 'ERR_INVALID_OPT_VALUE_ENCODING' ,
10911098 'The value "%s" is invalid for option "encoding"' , TypeError ) ;
1092- E ( 'ERR_INVALID_PACKAGE_CONFIG' ,
1093- `Invalid package config %s${ sep } package.json, %s` , Error ) ;
1094- E ( 'ERR_INVALID_PACKAGE_TARGET' , ( pkgPath , key , subpath , target ) => {
1095- if ( key === '.' ) {
1096- return `Invalid "exports" main target ${ JSONStringify ( target ) } defined ` +
1099+ E ( 'ERR_INVALID_PACKAGE_CONFIG' , ( path , message , hasMessage = true ) => {
1100+ if ( hasMessage )
1101+ return `Invalid package config ${ path } ${ sep } package.json, ${ message } ` ;
1102+ else
1103+ return `Invalid JSON in ${ path } imported from ${ message } ` ;
1104+ } , Error ) ;
1105+ E ( 'ERR_INVALID_PACKAGE_TARGET' ,
1106+ ( pkgPath , key , subpath , target , base = undefined ) => {
1107+ if ( key === null ) {
1108+ if ( subpath !== '' ) {
1109+ return `Invalid "exports" target ${ JSONStringify ( target ) } defined ` +
1110+ `for '${ subpath } ' in the package config ${ pkgPath } imported from ` +
1111+ base ;
1112+ } else {
1113+ return `Invalid "exports" main target ${ target } defined in the ` +
1114+ `package config ${ pkgPath } imported from ${ base } .` ;
1115+ }
1116+ } else if ( key === '.' ) {
1117+ return `Invalid "exports" main target ${ JSONStringify ( target ) } defined ` +
10971118 `in the package config ${ pkgPath } ${ sep } package.json` ;
1098- } else {
1099- return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
1100- StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
1119+ } else {
1120+ return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
1121+ StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
11011122 `package config ${ pkgPath } ${ sep } package.json` ;
1102- }
1103- } , Error ) ;
1123+ }
1124+ } , Error ) ;
11041125E ( 'ERR_INVALID_PERFORMANCE_MARK' ,
11051126 'The "%s" performance mark has not been set' , Error ) ;
11061127E ( 'ERR_INVALID_PROTOCOL' ,
@@ -1211,6 +1232,9 @@ E('ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK',
12111232 'The ES Module loader may not return a format of \'dynamic\' when no ' +
12121233 'dynamicInstantiate function was provided' , Error ) ;
12131234E ( 'ERR_MISSING_OPTION' , '%s is required' , TypeError ) ;
1235+ E ( 'ERR_MODULE_NOT_FOUND' , ( path , base , type = 'package' ) => {
1236+ return `Cannot find ${ type } '${ path } ' imported from ${ base } ` ;
1237+ } , Error ) ;
12141238E ( 'ERR_MULTIPLE_CALLBACK' , 'Callback called multiple times' , Error ) ;
12151239E ( 'ERR_NAPI_CONS_FUNCTION' , 'Constructor must be a function' , TypeError ) ;
12161240E ( 'ERR_NAPI_INVALID_DATAVIEW_ARGS' ,
@@ -1245,12 +1269,15 @@ E('ERR_OUT_OF_RANGE',
12451269 msg += ` It must be ${ range } . Received ${ received } ` ;
12461270 return msg ;
12471271 } , RangeError ) ;
1248- E ( 'ERR_PACKAGE_PATH_NOT_EXPORTED' , ( pkgPath , subpath ) => {
1272+ E ( 'ERR_PACKAGE_PATH_NOT_EXPORTED' , ( pkgPath , subpath , base = undefined ) => {
12491273 if ( subpath === '.' ) {
12501274 return `No "exports" main resolved in ${ pkgPath } ${ sep } package.json` ;
1251- } else {
1275+ } else if ( base === undefined ) {
12521276 return `Package subpath '${ subpath } ' is not defined by "exports" in ${
12531277 pkgPath } ${ sep } package.json`;
1278+ } else {
1279+ return `Package subpath '${ subpath } ' is not defined by "exports" in ${
1280+ pkgPath } imported from ${ base } `;
12541281 }
12551282} , Error ) ;
12561283E ( 'ERR_REQUIRE_ESM' ,
0 commit comments