From 9d3201748d53fbeb4650d0a72f3ff07efc13e89a Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Thu, 19 Oct 2023 09:59:05 -0600 Subject: [PATCH] fix(react): Update error message for invalid remote name --- packages/angular/src/utils/mf/utils.ts | 9 ++++++++- packages/react/src/module-federation/utils.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/angular/src/utils/mf/utils.ts b/packages/angular/src/utils/mf/utils.ts index b63c5e061dec27..1e67fc9cba352d 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 project "${remote}". Check that the name is correct in module-federation config file.\n` + ); + } const serveTarget = remoteConfiguration?.targets?.[target]; if (!serveTarget) { diff --git a/packages/react/src/module-federation/utils.ts b/packages/react/src/module-federation/utils.ts index 85e6c0e0b6fa90..82de463d160599 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 project "${remote}". Check that the name is correct in module-federation config file.\n` + ); + } const serveTarget = remoteConfiguration?.targets?.[target]; if (!serveTarget) {