Jamie
Jamie

Reputation: 168

.Net Core 3.0 Angular SSR Project not running

I have a .net core 3.0 project with an angular 8 frontend that uses webpack.

I need to enable server side rendering on the angular project for SEO and other indexing reasons but I am not able to get the project to run with server side rendering enabled.

I encounter various errors, see below. But ultimately it would be good if someone could point me in the right direction or let me know if SSR is achievable in .net core 3.0, if not then I can use 2.2 if it means SSR will work.

I have actually been able to get a .net core 2.2 angular SSR project to work but as soon as I do a HTTO get on anything other than the index page through postman, it returns 404 "Cannot get". Here is the .Net Core 2.2 project I have been able to make work.

Here is one of the tutorials I have followed which uses .Net Core 2.2.

Also, it seems that app.UseSpaPrerendering is now deprecated in .Net Core 3.0, and I cannot find any documentation on how to make SSR work without it.

Here is the main error I encounter when trying to run the test project which I followed the above tutorial to build:

NodeInvocationException: Prerendering failed because of error: Error: The module at main.js does not export a default function, and you have not specified which export to invoke.

There seems to be very little documentation on .net core + angular SSR so any advice would be appreciated.

Upvotes: 2

Views: 1471

Answers (1)

wodzu
wodzu

Reputation: 3172

I followed this article's instructions and it works like a charm for netcore 3.1. It also mentions your NodeInvocationException. According to the author this happens, "when your app starts to run before the Angular CLI server has finished building the app server-side".

It works despite the deprecation warning that you will get for UseSpaPrerendering().

PS: I had also to set the build action for main.server.ts and main.ts. Maybe the author just forgot to mention it.

Upvotes: 1

Related Questions