Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/build): handle undefined getOrCreateAngularServerApp during error compilation #29908

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ export function createAngularSsrInternalMiddleware(
const { writeResponseToNodeResponse, createWebRequestFromNodeRequest } =
await loadEsmModule<typeof import('@angular/ssr/node')>('@angular/ssr/node');

// The following is necessary because accessing the module after invalidation may result in an empty module,
// which can trigger a `TypeError: ɵgetOrCreateAngularServerApp is not a function` error.
// TODO: look into why.
await server.ssrLoadModule('/main.server.mjs');

const { ɵgetOrCreateAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs')) as {
ɵgetOrCreateAngularServerApp: typeof getOrCreateAngularServerApp;
};

// `ɵgetOrCreateAngularServerApp` can be undefined right after an error.
// See: https://github.com/angular/angular-cli/issues/29907
if (!ɵgetOrCreateAngularServerApp) {
return next();
}

const angularServerApp = ɵgetOrCreateAngularServerApp({
allowStaticRouteRender: true,
});
Expand Down