-1

I want to use angular universal in my project. Affter i added it I see error:

ReferenceError: window is not defined

I am not using window in my project, but maybe it uses in thirty part library. How to solve this problem?

I already saw simular qustion: Angular 9 Universal ReferenceError: window is not defined its answer doesn't help.

Adam
  • 486
  • 1
  • 7
  • 19
  • 1
    Try checking the exception call stack to see where the error is coming from. – Allan Juan Sep 13 '22 at 11:26
  • I found library witch useses windows web-audio-daw. Ok I can replace by another. But there is a lot of libraries witch useses window, and not every has alternative. What need to do in this case? – Adam Sep 13 '22 at 17:05

1 Answers1

0

Encapsulate the code with a check using isPlatformServer

export class ArtistShowComponent {
  constructor(@Inject(PLATFORM_ID) private platformId: Object) {
    this.isServerSide = isPlatformServer(platformId);
  }

  isServerSide: boolean;

  doSomething() {
    // If the issue is in typescript
    if (this.isServerSide) {
      ...
    }
  }
}

If the issue is in a third-party angular component / HTML:

<!-- Remove the component from the DOM -->
<ng-carousel *ngIf="!isServerSide"></div>
Pieterjan
  • 2,738
  • 4
  • 28
  • 55