0

I am not able to run SSR server due to the following errors, I've attached the main.js file and the error log

Steps I've followed to produce main build

npm run build:ssr

error when running the SSR server were

/home/suhayb/repos/hisas/web-app/dist/web-app-server/main.js:4680
dayjs_1.default.extend(relativeTime_1.default);
                ^
TypeError: Cannot read property 'extend' of undefined

1 Answer 1

1

So it seems dayjs is not supporting SSR.In Server side you cannot access DOM, window, localstorage... Solution: use dayjs specific methods with conditions if it is browser only. Example:

import { PLATFORM_ID, Inject } from '@angular/core';
import { isPlatformBrowser} from '@angular/common';
...
export class MyComponent {
...
    testBrowser: boolean;
    constructor(
        @Inject(PLATFORM_ID) platformId: string) {
            this.testBrowser = isPlatformBrowser(platformId);
            if (this.testBrowser) {
                //this is only executed on the browser

            }
    }
...
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.