Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference Error: window is not defined Angular 14 #99

Open
nikxco opened this issue Nov 20, 2022 · 3 comments
Open

Reference Error: window is not defined Angular 14 #99

nikxco opened this issue Nov 20, 2022 · 3 comments

Comments

@nikxco
Copy link

nikxco commented Nov 20, 2022

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

@BenceUszkai
Copy link

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

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

@jigneshzala
Copy link

still getting same error

@dirk-jacobs
Copy link

dirk-jacobs commented Apr 21, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants