From 76926680898b792e2b4104bb4f7b1135e8902e56 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Mon, 23 Oct 2023 09:09:22 -0600 Subject: [PATCH] fix(react): Update error message for invalid remote name (#19744) (cherry picked from commit 022f1ea355253aa7c87465a0e4eb541bee7a7be3) --- packages/angular/src/utils/mf/utils.ts | 9 ++++++++- packages/nx/src/project-graph/project-graph.ts | 6 +++++- packages/react/src/module-federation/utils.ts | 9 ++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) 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) {