Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: window is not defined , angular6 universal

I have an angular6 universal application, I am integrating ng-simple-slideshow for the image slider, it's building successful, but while running: npm run serve: SSR giving below error: please suggest some solution.thanks

ReferenceError: window is not defined
at F:\new_trd_back_up\dist\server.js:247023:8032
at vt (F:\new_trd_back_up\dist\server.js:246852:163)
at Object.module.exports (F:\new_trd_back_up\dist\server.js:246852:177)
at __webpack_require__ (F:\new_trd_back_up\dist\server.js:20:30)
at Object.jspdf (F:\new_trd_back_up\dist\server.js:87271:18)
at __webpack_require__ (F:\new_trd_back_up\dist\server.js:59361:30)
at Object../src/app/presentation/presentation.component.ts (F:\new_trd_back_up\dist\server.js:81159:13)
at __webpack_require__ (F:\new_trd_back_up\dist\server.js:59361:30)
at Object../src/app/presentation/presentation.component.ngfactory.js (F:\new_trd_back_up\dist\server.js:81046:11)
at __webpack_require__ (F:\new_trd_back_up\dist\server.js:59361:30)
like image 607
therightdoctors Avatar asked Aug 23 '18 12:08

therightdoctors


1 Answers

This also can be solved by using Dominos.

Add this to 'server.ts':

const domino = require('domino');
const fs = require('fs');
const path = require('path');
const template = fs.readFileSync(path.join(__dirname, '.', 'dist', 'index.html')).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['document'] = win.document;

Ticket's issue and suggestion on Github

like image 67
Remy Avatar answered Oct 11 '22 09:10

Remy