File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
packages/runtime/src/modules Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -232,7 +232,22 @@ export const getModuleEntryPoint = async (
232232 ) ;
233233 const pkg = JSON . parse ( pkgRaw ) ;
234234
235- const main = pkg . exports ?. [ '.' ] ?. import ?? pkg . main ?? 'index.js' ;
235+ // Find the best ESM entrypoint
236+ // https://nodejs.org/api/packages.html#package-entry-points
237+ let esm ;
238+ if ( typeof pkg . exports === 'string' ) {
239+ esm = pkg . exports ;
240+ } else {
241+ const exportsField = pkg . exports ?. [ '.' ] ;
242+ esm =
243+ typeof exportsField === 'string' ? exportsField : exportsField ?. import ;
244+ }
245+
246+ // main might point to esm or cjs, but in our adaptors it points to CJS
247+ const cjsProbably = pkg . main ;
248+
249+ const main = esm ?? cjsProbably ?? 'index.js' ;
250+
236251 const p = path . resolve ( moduleRoot , main ) ;
237252
238253 return { path : p , version : pkg . version } ;
You can’t perform that action at this time.
0 commit comments