I have a large application that was working with SSR using ngExpressEngine
in Angular 8. I ran though all the upgrade procedures described, but my server.ts
file was not properly migrated. Specifically the reference to provideModuleMap
remained (which is no longer supported in Angular 9).
Note that my routes were all correctly updated to use the new .then
system for lazy routes. Also note that it compiles fine and ng serve
works correctly. This problem only arises when I try to run the SSR package from express.
My problem can be isolated to what was, in Angular 8, these lines of code:
// * NOTE :: leave this as require() since this file is built Dynamically
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
To attempt to get this to work in Angular 9 I removed the call to provideModuleMap(LAZY_MODULE_MAP)
and just passed in LAZY_MODULE_MAP
, but that doesn't work as it seems LAZY_MODULE_MAP
isn't generated at all anymore.
...so with my change for Angular 9 I get the typical errors you'd expect from things trying to run server side that can only run client side. Namely ReferenceError: window is not defined
.
So how do I tell Angular 9 what modules shouldn't be prepared for SSR, as was possible in Angular 8?