From ccf71fd32b23019ae5e1621bae669bc6ae68614e Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Tue, 1 Oct 2024 13:55:26 +0100 Subject: [PATCH] fix(module-federation): exports could be objects and not strings #28129 (#28215) ## Current Behavior Exports defined in `package.json` of packages could be objects rather than strings such that we could see both: ```json { "exports": { ".": { "default": "./src/index.js" }, "index": { "default": { "default": "./src/index.js" } } } } ``` ## Expected Behavior The logic currently assumes it can only be a string. Ensure it checks if an object exists first ## Related Issue(s) Fixes #28129 --- .../src/utils/module-federation/secondary-entry-points.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/webpack/src/utils/module-federation/secondary-entry-points.ts b/packages/webpack/src/utils/module-federation/secondary-entry-points.ts index 4226c64bb16bf..9b2b8c06b5bef 100644 --- a/packages/webpack/src/utils/module-federation/secondary-entry-points.ts +++ b/packages/webpack/src/utils/module-federation/secondary-entry-points.ts @@ -115,7 +115,12 @@ function collectPackagesFromExports( }[] ): void { for (const [relativeEntryPoint, exportOptions] of Object.entries(exports)) { - if (exportOptions?.['default']?.search(/\.(js|mjs|cjs)$/)) { + const defaultExportOptions = + typeof exportOptions?.['default'] === 'string' + ? exportOptions?.['default'] + : exportOptions?.['default']?.['default']; + + if (defaultExportOptions?.search(/\.(js|mjs|cjs)$/)) { let entryPointName = joinPathFragments(pkgName, relativeEntryPoint); if (entryPointName.endsWith('.json')) { entryPointName = dirname(entryPointName);