maciejtreder / ng-toolkit

:star: Angular tool-box! Start your PWA in two steps! Add Serverless support for existing projects and much more
https://www.angular-universal-pwa.maciejtreder.com
MIT License
1.12k stars 157 forks source link

Unable to run server ( Element is not defined ) #560

Open prashant-93 opened 5 years ago

prashant-93 commented 5 years ago

Hi, While i am running the command npm run server getting the following error. `/home/prashant/pickrr_poker/hitrr/dist/server.js:146244 var elProto = Element.prototype; ^

ReferenceError: Element is not defined at /home/prashant/pickrr_poker/hitrr/dist/server.js:146244:19 at /home/prashant/pickrr_poker/hitrr/dist/server.js:145804:30 at Object. (/home/prashant/pickrr_poker/hitrr/dist/server.js:145806:2) at webpack_require (/home/prashant/pickrr_poker/hitrr/dist/server.js:21:30) at Object.uikit (/home/prashant/pickrr_poker/hitrr/dist/server.js:132867:18) at webpack_require (/home/prashant/pickrr_poker/hitrr/dist/server.js:129583:30) at Object../src/app/game-tables/user-wallet/user-wallet.component.ts (/home/prashant/pickrr_poker/hitrr/dist/server.js:131623:15) at webpack_require (/home/prashant/pickrr_poker/hitrr/dist/server.js:129583:30) at Object../src/app/game-tables/user-wallet/user-wallet.component.ngfactory.js (/home/prashant/pickrr_poker/hitrr/dist/server.js:131572:10) at webpack_require (/home/prashant/pickrr_poker/hitrr/dist/server.js:129583:30) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! hitrr@0.0.0 server: node local.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the hitrr@0.0.0 server script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/prashant/.npm/_logs/2019-01-28T09_09_41_856Z-debug.log`

Environment

Angular version: 7.0.1

Angular CLI: 7.0.3 Node: 8.11.3

Ubuntu 18.04

Others: { "@angular/animations": "^7.1.4", "@angular/common": "^7.1.4", "@angular/compiler": "^7.1.4", "@angular/core": "^7.1.4", "@angular/forms": "^7.1.4", "@angular/http": "^7.1.4", "@angular/platform-browser": "^7.1.4", "@angular/platform-browser-dynamic": "^7.1.4", "@angular/platform-server": "^7.1.4", "@angular/router": "^7.1.4", "@ng-toolkit/serverless": "^1.1.28", "@ng-toolkit/universal": "^1.1.50", "@nguniversal/common": "~7.0.0", "@nguniversal/express-engine": "~7.0.0", "@nguniversal/module-map-ngfactory-loader": "~7.0.0", "animejs": "^2.2.0", "core-js": "^2.6.1", "cors": "~2.8.4", "cp-cli": "^1.1.0", "express": "^4.16.4", "firebase-functions": "^2.1.0", "moment": "^2.23.0", "node-sass": "^4.11.0", "rxjs": "~6.3.3", "ts-loader": "4.2.0", "tslib": "^1.9.0", "uikit": "^3.0.0-rc.26", "webpack-cli": "^3.1.2", "zone.js": "~0.8.26" }

AbuHani commented 5 years ago

add this code to server.ts before enableProdMode()

` import { join } from 'path';

const DIST_FOLDER = join(process.cwd(), 'dist'); const domino = require('domino'); const fs = require('fs'); const template = fs .readFileSync(join(DIST_FOLDER, 'browser', 'index.html')) .toString(); const win = domino.createWindow(template);

global['window'] = win; global['HTMLElement'] = win.HTMLElement; global['Element'] = win.Element; `