0

I'm using Angular 10 and trying to implement SSR in my project.

When I run the npm run serve:ssr I'm getting the below error**

ReferenceError: window is not defined
        at Object.ujAs (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:12592766)
        at __webpack_require__ (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:317)
        at Object.Tczp (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:5962756)
        at __webpack_require__ (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:317)
        at Module.uj+Y (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:11877693)
        at __webpack_require__ (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:317)
        at Object.0 (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:180672)
        at __webpack_require__ (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:317)
        at +7ve (/Users/NAVEEN/Documents/workspace/Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:2383)
        at Object.<anonymous> (/Users/NAVEEN/Documents/workspace/`enter code here`Angular-New-Mockup/dist/nice-admin-angular/server/main.js:1:2428)

I have tried all the possibility from google search still getting the same error, Please guide me how to resolve this issue.

Naveenkumar A
  • 21
  • 1
  • 4

1 Answers1

0

Angular universal uses server side rendering. So if you try to use window in your code on the server side of the universal app, it won't be able to utilize it. Besides various third party libraries can also cause this problem.

If you only intend to use the window from browser then a work around can be a check for browser that is the client end.

For such cases in terms of third party library there are already posted questions. You can have a look at this one

window is not defined angular universal third library