FrozenPandaz / ng-universal-demo

171 stars 54 forks source link

Error in starting server #19

Open deepakzoto opened 7 years ago

deepakzoto commented 7 years ago

I copied the same settings from this repo. Why am i getting this error?

[nodemon] starting `node dist/server.js`
D:\GitWork\web-ui\dist\server.js:157900
var HTTP_PROTOCOL = (('https:' === document.location.protocol) ? 'https://' : 'http://');
                                   ^

ReferenceError: document is not defined
    at Object.<anonymous> (D:\GitWork\web-ui\dist\server.js:157900:36)
    at __webpack_require__ (D:\GitWork\web-ui\dist\server.js:26:30)
    at Object.<anonymous> (D:\GitWork\web-ui\dist\server.js:63718:73)
    at __webpack_require__ (D:\GitWork\web-ui\dist\server.js:26:30)
    at Object.<anonymous> (D:\GitWork\web-ui\dist\server.js:39936:94)
    at __webpack_require__ (D:\GitWork\web-ui\dist\server.js:26:30)
    at Object.<anonymous> (D:\GitWork\web-ui\dist\server.js:63332:75)
    at __webpack_require__ (D:\GitWork\web-ui\dist\server.js:26:30)
    at Object.<anonymous> (D:\GitWork\web-ui\dist\server.js:105998:82)
    at __webpack_require__ (D:\GitWork\web-ui\dist\server.js:26:30)
[nodemon] app crashed - waiting for file changes before starting...
ysus commented 7 years ago

https://github.com/mixpanel/mixpanel-js/issues/119

FrozenPandaz commented 7 years ago

Hi the document does not exist on the server as it does on the browser. This library should probably not be on the server. If the functionality is desired on the server either find a node version of the library or substitute it with your own.

deepakzoto commented 7 years ago

I removed mixpanel from my project. But I am also using angular 2 material and getting this error now:

GET: /: 308.202ms ERROR { ReferenceError: document is not defined at DefaultDomRenderer2.selectRootElement (D:\GitWork\web-ui\dist\server.js:37319:72) at createElement (D:\GitWork\web-ui\dist\server.js:10091:23) at createViewNodes (D:\GitWork\web-ui\dist\server.js:12769:44) at createRootView (D:\GitWork\web-ui\dist\server.js:12716:5) at Object.createProdRootView [as createRootView] (D:\GitWork\web-ui\dist\server.js:13377:12) at ComponentFactory_.create (D:\GitWork\web-ui\dist\server.js:10637:46) at ComponentFactoryBoundToModule.create (D:\GitWork\web-ui\dist\server.js:4173:29) at ApplicationRef_.bootstrap (D:\GitWork\web-ui\dist\server.js:5757:57) at D:\GitWork\web-ui\dist\server.js:5546:79 at Array.forEach (native) at PlatformRef_._moduleDoBootstrap (D:\GitWork\web-ui\dist\server.js:5546:42) at D:\GitWork\web-ui\dist\server.js:5508:27 at ZoneDelegate.invoke (D:\GitWork\web-ui\dist\server.js:118248:26) at Object.onInvoke (D:\GitWork\web-ui\dist\server.js:4874:37) at ZoneDelegate.invoke (D:\GitWork\web-ui\dist\server.js:118247:32) at Zone.run (D:\GitWork\web-ui\dist\server.js:117998:43) at D:\GitWork\web-ui\dist\server.js:118675:57 at ZoneDelegate.invokeTask (D:\GitWork\web-ui\dist\server.js:118281:31) at Object.onInvokeTask (D:\GitWork\web-ui\dist\server.js:4865:37) at ZoneDelegate.invokeTask (D:\GitWork\web-ui\dist\server.js:118280:36) at Zone.runTask (D:\GitWork\web-ui\dist\server.js:118048:47) at drainMicroTaskQueue (D:\GitWork\web-ui\dist\server.js:118441:35) at ZoneTask.invoke (D:\GitWork\web-ui\dist\server.js:118347:25) at data.args.(anonymous function) (D:\GitWork\web-ui\dist\server.js:119131:25) at FSReqWrap.oncomplete (fs.js:114:15) __zone_symbol__currentTask: ZoneTask { _zone: Zone { _properties: [Object], _parent: [Object], _name: 'angular', _zoneDelegate: [Object] }, runCount: 0, _zoneDelegates: null, _state: 'notScheduled', type: 'microTask', source: 'Promise.then', data: undefined, scheduleFn: undefined, cancelFn: null, callback: [Function], invoke: [Function] } }. I know material is not compatible with universal. Can we use angular-ssr [https://www.npmjs.com/package/angular-ssr] to solve this problem ?