@@ -183,12 +183,6 @@ function legacyMainResolve(packageJSONUrl, packageConfig, base) {
183
183
184
184
const baseStringified = isURL ( base ) ? base . href : base ;
185
185
186
- if ( typeof packageConfig . main !== 'string' ) {
187
- throw new ERR_INVALID_PACKAGE_CONFIG (
188
- fileURLToPath ( packageJSONUrl ) , base ,
189
- '"main" must be a string' , 'main' ) ;
190
- }
191
-
192
186
const resolvedOption = FSLegacyMainResolve ( packageJsonUrlString , packageConfig . main , baseStringified ) ;
193
187
194
188
const baseUrl = resolvedOption <= legacyMainResolveExtensionsIndexes . kResolvedByMainIndexNode ? `./${ packageConfig . main } ` : '' ;
@@ -769,6 +763,13 @@ function packageResolve(specifier, base, conditions) {
769
763
770
764
// Package match.
771
765
const packageConfig = packageJsonReader . read ( packageJSONPath , { __proto__ : null , specifier, base, isESM : true } ) ;
766
+ const invalid = packageConfig . main === undefined && packageConfig . exports === undefined ;
767
+ if ( invalid ) {
768
+ throw new ERR_INVALID_PACKAGE_CONFIG (
769
+ fileURLToPath ( packageJSONUrl ) , base ,
770
+ 'package.json must have a "main" or "exports" field'
771
+ ) ;
772
+ }
772
773
if ( packageConfig . exports != null ) {
773
774
return packageExportsResolve (
774
775
packageJSONUrl , packageSubpath , packageConfig , base , conditions ) ;
0 commit comments