diff --git a/packages/angular/src/utils/mf/utils.ts b/packages/angular/src/utils/mf/utils.ts index b63c5e061dec2..58f98741004c2 100644 --- a/packages/angular/src/utils/mf/utils.ts +++ b/packages/angular/src/utils/mf/utils.ts @@ -48,7 +48,14 @@ export function getFunctionDeterminateRemoteUrl(isServer: boolean = false) { const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.mjs'; return function (remote: string) { - const remoteConfiguration = readCachedProjectConfiguration(remote); + let remoteConfiguration = null; + try { + remoteConfiguration = readCachedProjectConfiguration(remote); + } catch (e) { + throw new Error( + `Cannot find remote "${remote}". Check that the remote name is correct in your module federation config file.\n` + ); + } const serveTarget = remoteConfiguration?.targets?.[target]; if (!serveTarget) { diff --git a/packages/nx/src/project-graph/project-graph.ts b/packages/nx/src/project-graph/project-graph.ts index f8dcd65a00370..1bf09aaffa00b 100644 --- a/packages/nx/src/project-graph/project-graph.ts +++ b/packages/nx/src/project-graph/project-graph.ts @@ -50,7 +50,11 @@ export function readCachedProjectConfiguration( ): ProjectConfiguration { const graph = readCachedProjectGraph(); const node = graph.nodes[projectName]; - return node.data; + try { + return node.data; + } catch (e) { + throw new Error(`Cannot find project: '${projectName}' in your workspace.`); + } } /** diff --git a/packages/react/src/module-federation/utils.ts b/packages/react/src/module-federation/utils.ts index 85e6c0e0b6fa9..b70941e8243a7 100644 --- a/packages/react/src/module-federation/utils.ts +++ b/packages/react/src/module-federation/utils.ts @@ -21,7 +21,14 @@ export function getFunctionDeterminateRemoteUrl(isServer: boolean = false) { const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js'; return function (remote: string) { - const remoteConfiguration = readCachedProjectConfiguration(remote); + let remoteConfiguration = null; + try { + remoteConfiguration = readCachedProjectConfiguration(remote); + } catch (e) { + throw new Error( + `Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n` + ); + } const serveTarget = remoteConfiguration?.targets?.[target]; if (!serveTarget) {