Skip to content

Commit 45dea6f

Browse files
committed
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 1f119be)
1 parent 4e2b23f commit 45dea6f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/angular_devkit/build_angular/src/builders/prerender/routes-extractor-worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function extract(): Promise<string[]> {
4747
const bootstrapAppFnOrModule = bootstrapAppFn || AppServerModule;
4848
assert(
4949
bootstrapAppFnOrModule,
50-
`Neither an AppServerModule nor a bootstrapping function was exported from: ${serverBundlePath}.`,
50+
`The file "${serverBundlePath}" does not have a default export for an AppServerModule or a bootstrapping function.`,
5151
);
5252

5353
const routes: string[] = [];

packages/angular_devkit/build_angular/src/utils/server-rendering/render-page.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import type { ApplicationRef, StaticProvider } from '@angular/core';
10+
import assert from 'node:assert';
1011
import { basename } from 'node:path';
1112
import { loadEsmModule } from '../load-esm';
1213
import { MainServerBundleExports, RenderUtilsServerBundleExports } from './main-bundle-exports';
@@ -73,6 +74,10 @@ export async function renderPage({
7374
];
7475

7576
let html: string | undefined;
77+
assert(
78+
bootstrapAppFnOrModule,
79+
'The file "./main.server.mjs" does not have a default export for an AppServerModule or a bootstrapping function.',
80+
);
7681

7782
if (isBootstrapFn(bootstrapAppFnOrModule)) {
7883
html = await renderApplication(bootstrapAppFnOrModule, {

0 commit comments

Comments
 (0)