@@ -183,12 +183,6 @@ function legacyMainResolve(packageJSONUrl, packageConfig, base) {
183183
184184 const baseStringified = isURL ( base ) ? base . href : base ;
185185
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-
192186 const resolvedOption = FSLegacyMainResolve ( packageJsonUrlString , packageConfig . main , baseStringified ) ;
193187
194188 const baseUrl = resolvedOption <= legacyMainResolveExtensionsIndexes . kResolvedByMainIndexNode ? `./${ packageConfig . main } ` : '' ;
@@ -769,6 +763,13 @@ function packageResolve(specifier, base, conditions) {
769763
770764 // Package match.
771765 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+ }
772773 if ( packageConfig . exports != null ) {
773774 return packageExportsResolve (
774775 packageJSONUrl , packageSubpath , packageConfig , base , conditions ) ;
0 commit comments