File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed 
packages/react-native-builder-bob/src/utils Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -71,11 +71,13 @@ export default async function compile({
7171
7272  await  fs . mkdirp ( output ) ; 
7373
74-   if  ( ! esm )  { 
75-     // Ideally we should code with ESM syntax as CommonJS if `esm` is not enabled 
76-     // This maintain compatibility with code written for CommonJS 
77-     // However currently NextJS has non-standard behavior and breaks this 
78-     // So for now we only set this conditionally 
74+   // Imports are not rewritten to include the extension if `esm` is not enabled 
75+   // Ideally we should always treat ESM syntax as CommonJS if `esm` is not enabled 
76+   // This would maintain compatibility for legacy setups where `import`/`export` didn't require file extensions 
77+   // However NextJS has non-standard behavior and breaks if we add `type: 'commonjs'` for code with import/export 
78+   // So we skip generating `package.json` if `esm` is not enabled and `modules` is not `commonjs` 
79+   // This means that user can't use `type: 'module'` in root `package.json` without enabling `esm` for `module` target 
80+   if  ( esm  ||  modules  ===  'commonjs' )  { 
7981    await  fs . writeJSON ( path . join ( output ,  'package.json' ) ,  { 
8082      type : modules  ===  'commonjs'  ? 'commonjs'  : 'module' , 
8183    } ) ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments