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.
here it is throwing error in server.js file , how to fix it.
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! [email protected] serverrl `node local.js`
npm ERR! Exit status 1
as a workaround i replace window with global.
var work = global.document.createElement('div'); but window,document element is being used in many places of server.js
function(module, exports)
{
'use strict';
exports.__esModule = true;
var tagSoup = false;
var selfClose = false;
var work = window.document.createElement('div');
}
function isBrowser()
{
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
}
I expect window.document,window to be replaced by nodejs syntax for the above sample code.