File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed
packages/cli-v3/src/build Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -576,12 +576,31 @@ function isBuiltinModule(path: string): boolean {
576
576
return builtinModules . includes ( path . replace ( "node:" , "" ) ) ;
577
577
}
578
578
579
- async function hasNoEsmTypeMarkers ( filePath : string ) : Promise < boolean > {
579
+ async function isMainPackageJson ( filePath : string ) : Promise < boolean > {
580
580
try {
581
581
const packageJson = await readPackageJSON ( filePath ) ;
582
582
583
- // Exclude esm type markers. They look like this: { "type": "module" }
584
- return Object . keys ( packageJson ) . length > 1 || ! packageJson . type ;
583
+ // Allowlist of non-informative fields that can appear with 'type: module | commonjs' in marker package.json files
584
+ const markerFields = new Set ( [
585
+ "type" ,
586
+ "sideEffects" ,
587
+ "browser" ,
588
+ "main" ,
589
+ "module" ,
590
+ "react-native" ,
591
+ "name" ,
592
+ ] ) ;
593
+
594
+ if ( ! packageJson . type ) {
595
+ return true ;
596
+ }
597
+
598
+ const keys = Object . keys ( packageJson ) ;
599
+ if ( keys . every ( ( k ) => markerFields . has ( k ) ) ) {
600
+ return false ; // type marker
601
+ }
602
+
603
+ return true ;
585
604
} catch ( error ) {
586
605
if ( ! ( error instanceof Error ) ) {
587
606
logger . debug ( "[externals][containsEsmTypeMarkers] Unknown error" , {
@@ -619,7 +638,7 @@ async function findNearestPackageJson(
619
638
620
639
const [ error , packageJsonPath ] = await tryCatch (
621
640
resolvePackageJSON ( dirname ( basePath ) , {
622
- test : hasNoEsmTypeMarkers ,
641
+ test : isMainPackageJson ,
623
642
} )
624
643
) ;
625
644
You can’t perform that action at this time.
0 commit comments