@@ -1070,29 +1070,50 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError);
1070
1070
E ( 'ERR_INVALID_HANDLE_TYPE' , 'This handle type cannot be sent' , TypeError ) ;
1071
1071
E ( 'ERR_INVALID_HTTP_TOKEN' , '%s must be a valid HTTP token ["%s"]' , TypeError ) ;
1072
1072
E ( 'ERR_INVALID_IP_ADDRESS' , 'Invalid IP address: %s' , TypeError ) ;
1073
- E ( 'ERR_INVALID_MODULE_SPECIFIER' , ( pkgPath , subpath ) => {
1074
- assert ( subpath !== '.' ) ;
1075
- return `Package subpath '${ subpath } ' is not a valid module request for the ` +
1076
- `"exports" resolution of ${ pkgPath } ${ sep } package.json` ;
1073
+ E ( 'ERR_INVALID_MODULE_SPECIFIER' , ( pkgPath , subpath , base = undefined ) => {
1074
+ if ( subpath === undefined ) {
1075
+ return `Invalid package name '${ pkgPath } ' imported from ${ base } ` ;
1076
+ } else if ( base === undefined ) {
1077
+ assert ( subpath !== '.' ) ;
1078
+ return `Package subpath '${ subpath } ' is not a valid module request for ` +
1079
+ `the "exports" resolution of ${ pkgPath } ${ sep } package.json` ;
1080
+ } else {
1081
+ return `Package subpath '${ subpath } ' is not a valid module request for ` +
1082
+ `the "exports" resolution of ${ pkgPath } imported from ${ base } ` ;
1083
+ }
1077
1084
} , TypeError ) ;
1078
1085
E ( 'ERR_INVALID_OPT_VALUE' , ( name , value ) =>
1079
1086
`The value "${ String ( value ) } " is invalid for option "${ name } "` ,
1080
1087
TypeError ,
1081
1088
RangeError ) ;
1082
1089
E ( 'ERR_INVALID_OPT_VALUE_ENCODING' ,
1083
1090
'The value "%s" is invalid for option "encoding"' , TypeError ) ;
1084
- E ( 'ERR_INVALID_PACKAGE_CONFIG' ,
1085
- `Invalid package config %s${ sep } package.json, %s` , Error ) ;
1086
- E ( 'ERR_INVALID_PACKAGE_TARGET' , ( pkgPath , key , subpath , target ) => {
1087
- if ( key === '.' ) {
1088
- return `Invalid "exports" main target ${ JSONStringify ( target ) } defined ` +
1091
+ E ( 'ERR_INVALID_PACKAGE_CONFIG' , ( path , message , hasMessage = true ) => {
1092
+ if ( hasMessage )
1093
+ return `Invalid package config ${ path } ${ sep } package.json, ${ message } ` ;
1094
+ else
1095
+ return `Invalid JSON in ${ path } imported from ${ message } ` ;
1096
+ } , Error ) ;
1097
+ E ( 'ERR_INVALID_PACKAGE_TARGET' ,
1098
+ ( pkgPath , key , subpath , target , base = undefined ) => {
1099
+ if ( key === null ) {
1100
+ if ( subpath !== '' ) {
1101
+ return `Invalid "exports" target ${ JSONStringify ( target ) } defined ` +
1102
+ `for '${ subpath } ' in the package config ${ pkgPath } imported from ` +
1103
+ base ;
1104
+ } else {
1105
+ return `Invalid "exports" main target ${ target } defined in the ` +
1106
+ `package config ${ pkgPath } imported from ${ base } .` ;
1107
+ }
1108
+ } else if ( key === '.' ) {
1109
+ return `Invalid "exports" main target ${ JSONStringify ( target ) } defined ` +
1089
1110
`in the package config ${ pkgPath } ${ sep } package.json` ;
1090
- } else {
1091
- return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
1092
- StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
1111
+ } else {
1112
+ return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
1113
+ StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
1093
1114
`package config ${ pkgPath } ${ sep } package.json` ;
1094
- }
1095
- } , Error ) ;
1115
+ }
1116
+ } , Error ) ;
1096
1117
E ( 'ERR_INVALID_PERFORMANCE_MARK' ,
1097
1118
'The "%s" performance mark has not been set' , Error ) ;
1098
1119
E ( 'ERR_INVALID_PROTOCOL' ,
@@ -1203,6 +1224,9 @@ E('ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK',
1203
1224
'The ES Module loader may not return a format of \'dynamic\' when no ' +
1204
1225
'dynamicInstantiate function was provided' , Error ) ;
1205
1226
E ( 'ERR_MISSING_OPTION' , '%s is required' , TypeError ) ;
1227
+ E ( 'ERR_MODULE_NOT_FOUND' , ( path , base , type = 'package' ) => {
1228
+ return `Cannot find ${ type } '${ path } ' imported from ${ base } ` ;
1229
+ } , Error ) ;
1206
1230
E ( 'ERR_MULTIPLE_CALLBACK' , 'Callback called multiple times' , Error ) ;
1207
1231
E ( 'ERR_NAPI_CONS_FUNCTION' , 'Constructor must be a function' , TypeError ) ;
1208
1232
E ( 'ERR_NAPI_INVALID_DATAVIEW_ARGS' ,
@@ -1237,12 +1261,15 @@ E('ERR_OUT_OF_RANGE',
1237
1261
msg += ` It must be ${ range } . Received ${ received } ` ;
1238
1262
return msg ;
1239
1263
} , RangeError ) ;
1240
- E ( 'ERR_PACKAGE_PATH_NOT_EXPORTED' , ( pkgPath , subpath ) => {
1264
+ E ( 'ERR_PACKAGE_PATH_NOT_EXPORTED' , ( pkgPath , subpath , base = undefined ) => {
1241
1265
if ( subpath === '.' ) {
1242
1266
return `No "exports" main resolved in ${ pkgPath } ${ sep } package.json` ;
1243
- } else {
1267
+ } else if ( base === undefined ) {
1244
1268
return `Package subpath '${ subpath } ' is not defined by "exports" in ${
1245
1269
pkgPath } ${ sep } package.json`;
1270
+ } else {
1271
+ return `Package subpath '${ subpath } ' is not defined by "exports" in ${
1272
+ pkgPath } imported from ${ base } `;
1246
1273
}
1247
1274
} , Error ) ;
1248
1275
E ( 'ERR_REQUIRE_ESM' ,
0 commit comments