ngx-masonry icon indicating copy to clipboard operation
ngx-masonry copied to clipboard

Reference Error: window is not defined Angular 14

Open nikxco opened this issue 2 years ago • 3 comments

ERROR Error: Uncaught (in promise): ReferenceError: window is not defined
ReferenceError: window is not defined

Getting ReferenceError for window with ssr build.

"@angular/animations": "^14.2.0",
"@angular/cdk": "^14.2.4",
"@angular/common": "^14.2.0",
"@angular/compiler": "^14.2.0",
"@angular/core": "^14.2.0",
"@angular/forms": "^14.2.0",
"@angular/material": "^14.2.4",
"@angular/platform-browser": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@angular/platform-server": "^14.2.0",
"@angular/router": "^14.2.0",
"@nguniversal/express-engine": "^14.2.0"
"masonry-layout": "^4.2.2",
"ngx-masonry": "^14.0.1"
import { NgxMasonryModule } from 'ngx-masonry';

@NgModule({
  declarations: [HomeComponent],
  imports: [
    NgxMasonryModule,
    CommonModule,
    AppRoutingModule,
    MatButtonModule,
    MatIconModule,
    MatCardModule,
  ],
})
export class AppModule {}

Is it not compatible with SSR? or am i missing something

nikxco avatar Nov 20 '22 21:11 nikxco

It is works with SSR. Add the following code to "server.ts":

    global['window'] = window;
    global['document'] = window.document;

BenceUszkai avatar Feb 13 '23 15:02 BenceUszkai

still getting same error

jigneshzala avatar Mar 10 '23 10:03 jigneshzala

I have the same issue with version 14. (With version 13 it works) I added the requested global definitions but I still have the issue

dirk-jacobs avatar Apr 21 '23 10:04 dirk-jacobs