From 45dea6f44cb27431e4767ce16df3e84c5b6d8f9c Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 23 Jan 2024 09:04:34 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): provide actionable error message when server bundle is missing default export This change improves the error message when the server bundle does not export a default export. Closes #26922 (cherry picked from commit 1f119be00d29765d35ef5942a89a2fe6c5a5155b) --- .../src/builders/prerender/routes-extractor-worker.ts | 2 +- .../build_angular/src/utils/server-rendering/render-page.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/build_angular/src/builders/prerender/routes-extractor-worker.ts b/packages/angular_devkit/build_angular/src/builders/prerender/routes-extractor-worker.ts index 1932f8f0ef1f..b032fc676809 100644 --- a/packages/angular_devkit/build_angular/src/builders/prerender/routes-extractor-worker.ts +++ b/packages/angular_devkit/build_angular/src/builders/prerender/routes-extractor-worker.ts @@ -47,7 +47,7 @@ async function extract(): Promise { const bootstrapAppFnOrModule = bootstrapAppFn || AppServerModule; assert( bootstrapAppFnOrModule, - `Neither an AppServerModule nor a bootstrapping function was exported from: ${serverBundlePath}.`, + `The file "${serverBundlePath}" does not have a default export for an AppServerModule or a bootstrapping function.`, ); const routes: string[] = []; diff --git a/packages/angular_devkit/build_angular/src/utils/server-rendering/render-page.ts b/packages/angular_devkit/build_angular/src/utils/server-rendering/render-page.ts index 44547f164320..a7cf0af1e577 100644 --- a/packages/angular_devkit/build_angular/src/utils/server-rendering/render-page.ts +++ b/packages/angular_devkit/build_angular/src/utils/server-rendering/render-page.ts @@ -7,6 +7,7 @@ */ import type { ApplicationRef, StaticProvider } from '@angular/core'; +import assert from 'node:assert'; import { basename } from 'node:path'; import { loadEsmModule } from '../load-esm'; import { MainServerBundleExports, RenderUtilsServerBundleExports } from './main-bundle-exports'; @@ -73,6 +74,10 @@ export async function renderPage({ ]; let html: string | undefined; + assert( + bootstrapAppFnOrModule, + 'The file "./main.server.mjs" does not have a default export for an AppServerModule or a bootstrapping function.', + ); if (isBootstrapFn(bootstrapAppFnOrModule)) { html = await renderApplication(bootstrapAppFnOrModule, {