diff --git a/packages/module-federation/src/utils/get-remotes-for-host.ts b/packages/module-federation/src/utils/get-remotes-for-host.ts index 663beefa6d..7f1a05fbd4 100644 --- a/packages/module-federation/src/utils/get-remotes-for-host.ts +++ b/packages/module-federation/src/utils/get-remotes-for-host.ts @@ -1,4 +1,4 @@ -import { logger, type ProjectGraph } from '@nx/devkit'; +import { logger, parseTargetString, type ProjectGraph } from '@nx/devkit'; import { registerTsProject } from '@nx/js/src/internal'; import { findMatchingProjects } from 'nx/src/utils/find-matching-projects'; import * as pc from 'picocolors'; @@ -59,8 +59,35 @@ function collectRemoteProjects( collected.add(remote); const remoteProjectRoot = remoteProject.root; + + // Find the target that uses the module-federation-dev-server executor + let buildTargetName = 'build'; + if (remoteProject.targets) { + for (const [targetKey, targetConfig] of Object.entries( + remoteProject.targets + )) { + const executor = targetConfig.executor || ''; + // Extract the portion after the `:` in the executor name + const executorParts = executor.split(':'); + const executorName = + executorParts.length > 1 ? executorParts[1] : executor; + + if (executorName === 'module-federation-dev-server') { + // Extract the buildTarget from the options + if (targetConfig.options?.buildTarget) { + const parsedTarget = parseTargetString( + targetConfig.options.buildTarget, + context.projectGraph + ); + buildTargetName = parsedTarget.target; + break; + } + } + } + } + let remoteProjectTsConfig = - remoteProject.targets['build'].options.tsConfig ?? + remoteProject.targets?.[buildTargetName]?.options?.tsConfig ?? [ join(remoteProjectRoot, 'tsconfig.app.json'), join(remoteProjectRoot, 'tsconfig.json'),