Skip to content

Commit 32b1dcd

Browse files
committedMar 21, 2025·
fix(@angular/build): handle undefined getOrCreateAngularServerApp during error compilation
Enhanced error handling to account for cases where `getOrCreateAngularServerApp` is undefined during the compilation process. This prevents unexpected crashes and improves build stability. Closes #29907 (cherry picked from commit a8817a3)
1 parent 20455e2 commit 32b1dcd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎packages/angular/build/src/tools/vite/middlewares/ssr-middleware.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ export function createAngularSsrInternalMiddleware(
4040
const { writeResponseToNodeResponse, createWebRequestFromNodeRequest } =
4141
await loadEsmModule<typeof import('@angular/ssr/node')>('@angular/ssr/node');
4242

43-
// The following is necessary because accessing the module after invalidation may result in an empty module,
44-
// which can trigger a `TypeError: ɵgetOrCreateAngularServerApp is not a function` error.
45-
// TODO: look into why.
46-
await server.ssrLoadModule('/main.server.mjs');
47-
4843
const { ɵgetOrCreateAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs')) as {
4944
ɵgetOrCreateAngularServerApp: typeof getOrCreateAngularServerApp;
5045
};
5146

47+
// `ɵgetOrCreateAngularServerApp` can be undefined right after an error.
48+
// See: https://github.com/angular/angular-cli/issues/29907
49+
if (!ɵgetOrCreateAngularServerApp) {
50+
return next();
51+
}
52+
5253
const angularServerApp = ɵgetOrCreateAngularServerApp({
5354
allowStaticRouteRender: true,
5455
});

0 commit comments

Comments
 (0)
Please sign in to comment.