Angular-Cli Spa Template. ServerSideRendering with --aot and Typescript 2.6 support #140

Closed
opened 2025-08-09 17:15:09 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @speige on 3/7/2018

The latest angular officially supports Typescript 2.6. If I use the latest angular-cli template & upgrade package.json to Typescript 2.6.2, everything works fine.

If I follow the SSR instructions from https://docs.microsoft.com/en-us/aspnet/core/spa/angular everything still works fine.

If I add --aot to "build:ssr" in package.json, I get an error.

If I downgrade to Typescript 2.5.3, everything works again, even with --aot.

ERROR in ./src/main.server.ts
Module parse failed: Unexpected token (18:21)
You may need an appropriate loader to handle this file type.
| core_1.enableProdMode();
| exports.default = aspnet_prerendering_1.createServerRenderer(function (params) {
| var _a = (module as any).exports, AppServerModule = _a.AppServerModule, AppServerModuleNgFactory = _a.AppServerModuleNgFactory, LAZY_MODULE_MAP = _a.LAZY_MODULE_MAP;
| var options = {
| document: params.data.originalHtml,

image

Not sure how important AOT is for server-side rendering (since it's not on by default in the template), but it seems like it'd be valuable to enable, if possible.

main.server.ts is a port to .net core from the node+express version at https://github.com/angular/angular/blob/master/aio/content/examples/universal/server.ts
I haven't tested the node+express version to see if it works with Typescript 2.6.2 & aot.

*Originally created by @speige on 3/7/2018* The latest angular officially supports Typescript 2.6. If I use the latest angular-cli template & upgrade package.json to Typescript 2.6.2, everything works fine. If I follow the SSR instructions from https://docs.microsoft.com/en-us/aspnet/core/spa/angular everything still works fine. If I add --aot to "build:ssr" in package.json, I get an error. If I downgrade to Typescript 2.5.3, everything works again, even with --aot. ERROR in ./src/main.server.ts Module parse failed: Unexpected token (18:21) You may need an appropriate loader to handle this file type. | core_1.enableProdMode(); | exports.default = aspnet_prerendering_1.createServerRenderer(function (params) { | var _a = (module as any).exports, AppServerModule = _a.AppServerModule, AppServerModuleNgFactory = _a.AppServerModuleNgFactory, LAZY_MODULE_MAP = _a.LAZY_MODULE_MAP; | var options = { | document: params.data.originalHtml, ![image](https://user-images.githubusercontent.com/2002030/37119052-7643a25c-2213-11e8-938a-cd46bc030f1a.png) Not sure how important AOT is for server-side rendering (since it's not on by default in the template), but it seems like it'd be valuable to enable, if possible. main.server.ts is a port to .net core from the node+express version at https://github.com/angular/angular/blob/master/aio/content/examples/universal/server.ts I haven't tested the node+express version to see if it works with Typescript 2.6.2 & aot.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#140
No description provided.