@@ -1104,18 +1104,28 @@ E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => {
11041104} , Error ) ;
11051105E ( 'ERR_INVALID_PACKAGE_TARGET' ,
11061106 ( pkgPath , key , subpath , target , base = undefined ) => {
1107+ const relError = typeof target === 'string'
1108+ && target . length && ! target . startsWith ( './' ) ;
11071109 if ( key === null ) {
11081110 if ( subpath !== '' ) {
11091111 return `Invalid "exports" target ${ JSONStringify ( target ) } defined ` +
11101112 `for '${ subpath } ' in the package config ${ pkgPath } imported from ` +
1111- base ;
1113+ ` ${ base } . ${ relError ? ' - targets must start with "./"' : '' } ` ;
11121114 } else {
11131115 return `Invalid "exports" main target ${ target } defined in the ` +
1114- `package config ${ pkgPath } imported from ${ base } .` ;
1116+ `package config ${ pkgPath } imported from ${ base } .${ relError ?
1117+ ' - targets must start with "./"' : '' } `;
11151118 }
11161119 } else if ( key === '.' ) {
11171120 return `Invalid "exports" main target ${ JSONStringify ( target ) } defined ` +
1118- `in the package config ${ pkgPath } ${ sep } package.json` ;
1121+ `in the package config ${ pkgPath } ${ sep } package.json${ relError ?
1122+ ' - targets must start with "./"' : '' } `;
1123+ } else if ( typeof target === 'string' && target !== '' &&
1124+ ! target . startsWith ( './' ) ) {
1125+ return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
1126+ StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
1127+ `package config ${ pkgPath } ${ sep } package.json. ` +
1128+ '- targets must start with `./`' ;
11191129 } else {
11201130 return `Invalid "exports" target ${ JSONStringify ( target ) } defined for '${
11211131 StringPrototypeSlice ( key , 0 , - subpath . length || key . length ) } ' in the ` +
0 commit comments