File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
packages/sandpack-core/src/resolver/utils Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ export function normalizePackageExport(
2525
2626export function extractPathFromExport (
2727 exportValue : PackageExportType ,
28- pkgRoot : string
28+ pkgRoot : string ,
29+ checkedExportKeys : string [ ] = EXPORTS_KEYS
2930) : string | false {
3031 if ( ! exportValue ) {
3132 return false ;
@@ -46,13 +47,17 @@ export function extractPathFromExport(
4647 }
4748
4849 if ( typeof exportValue === 'object' ) {
49- for ( const key of EXPORTS_KEYS ) {
50+ for ( const key of checkedExportKeys ) {
5051 const exportFilename = exportValue [ key ] ;
5152 if ( exportFilename !== undefined ) {
5253 if ( typeof exportFilename === 'string' ) {
5354 return normalizePackageExport ( exportFilename , pkgRoot ) ;
5455 }
55- return extractPathFromExport ( exportFilename , pkgRoot ) ;
56+ return extractPathFromExport (
57+ exportFilename ,
58+ pkgRoot ,
59+ checkedExportKeys
60+ ) ;
5661 }
5762 }
5863 return false ;
Original file line number Diff line number Diff line change @@ -8,6 +8,11 @@ const PKG_ALIAS_FIELDS = ['browser', 'alias'];
88
99type AliasesDict = { [ key : string ] : string } ;
1010
11+ const COMMONJS_EXPORT_KEYS = [ 'browser' , 'development' , 'default' , 'require' ] ;
12+ function forceCommonJs ( name : string , version : string ) : boolean {
13+ return name === 'chevrotain' && version . startsWith ( '10.' ) ;
14+ }
15+
1116export interface ProcessedPackageJSON {
1217 aliases : AliasesDict ;
1318 hasExports : boolean ;
@@ -43,7 +48,15 @@ export function processPackageJSON(
4348 } else if ( typeof content . exports === 'object' ) {
4449 const exportKeys = Object . keys ( content . exports ) ;
4550 if ( ! exportKeys [ 0 ] . startsWith ( '.' ) ) {
46- const resolvedExport = extractPathFromExport ( content . exports , pkgRoot ) ;
51+ const checkedExportKeys = forceCommonJs ( content . name , content . version )
52+ ? COMMONJS_EXPORT_KEYS
53+ : undefined ;
54+
55+ const resolvedExport = extractPathFromExport (
56+ content . exports ,
57+ pkgRoot ,
58+ checkedExportKeys
59+ ) ;
4760 if ( ! resolvedExport ) {
4861 throw new Error ( `Could not find a valid export for ${ pkgRoot } ` ) ;
4962 }
You can’t perform that action at this time.
0 commit comments