How to fix “ReferenceError: window is not defined” error in angular 6 universal server.js
See original GitHub issueI’m submitting a…
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
In package
[ ] @ng-toolkit/init
[ ] @ng-toolkit/serverless
[X] @ng-toolkit/universal
[ ] @ng-toolkit/pwa
[ ] @ng-toolkit/firebug
Current behavior
I execute the following command on angular cli command line tool, to install universal package for angular6 ‘ng add @ng-toolkit/universal’. It installed good,after that i execute npm run build:prod and it also runs very well. Now finally I run ‘npm run server’.But this throws me error without giving me launching url.
ReferenceError: window is not defined
at Object.exports.__esModule (D:\ANGULAR2\dist\server.js:122614:14)
at webpack_require (D:\ANGULAR2\dist\server.js:122314:31)
at Object.exports.__esModule (D:\ANGULAR2\dist\server.js:122359:19)
at webpack_require (D:\ANGULAR2\dist\server.js:122314:31)
at Object.exports.__esModule (D:\ANGULAR2\dist\server.js:122343:21)
at webpack_require (D:\ANGULAR2\dist\server.js:122314:31)
at D:\ANGULAR2\dist\server.js:122334:19
at D:\ANGULAR2\dist\server.js:122337:11
at webpackUniversalModuleDefinition (D:\ANGULAR2\dist\server.js:122292:21)
at Object.exports.__esModule (D:\ANGULAR2\dist\server.js:122294:4)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rssmtechwood@0.0.0 serverrl node local.js
npm ERR! Exit status 1
Expected behavior
when I run this command npm run server, I expect the following lines rssmtechwood@0.0.0 server:D:\ANGULAR2\rssmtechwood node local.js Listening on http://localhost:8080
Minimal reproduction of the problem with instructions
Step 1: I execute ng add @ng-toolkit/universal in angular/cli command prompt. Note: It produces server.js file automatically in dist folder. Step 2: Executes npm run build:prod Step 3: Finally he executes npm run server.
Example repository
What is the motivation / use case for changing the behavior?
Environment
Angular CLI: 6.2.9
Angular version: 6.1.0
- Node version: 8.12
- Platform: Windows 8.1
Others:
IDE- Visual Studio Code
Issue Analytics
- State:
- Created 4 years ago
- Comments:14
Top GitHub Comments
@gitulaga Ok, you don’t have to run Amazon ads in server side.
The only benefit that server side rendering brings to you, is being SEO friendly. In this case, it’s not important. Just skip it in server side and let Angular runs it in the client side.
For now you can close this issue.
Thanks, Vahidvdn so much… Actually, it is amazon ads not working in my site, if I comment then angular universal is working. Amazon ads are called by using postscribe package in my typescript code. I don’t know why it is not supporting for angular6 universal