ReferenceError: google is not defined Angular Universal SSR npm run server:ssr

Viewed 250

I am aware of the reason why google reference error is coming its because sever.js which is getting executed at the server does not have google defined in its scope. I am looking for a turnaround to fix this error.

After running npm run serve:ssr it gets this

task: ZoneTask {
    _zone: Zone {
      _parent: [Zone],
      _name: 'angular',
      _properties: [Object],
      _zoneDelegate: [ZoneDelegate]
    },
    runCount: 0,
    _zoneDelegates: null,
    _state: 'notScheduled',
    type: 'microTask',
    source: 'Promise.then',
    data: ZoneAwarePromise [Promise] {
      __zone_symbol__state: 0,
      __zone_symbol__value: ReferenceError: google is not defined
          at new exports.ListingsComponent (/home/abhishek/projects/website/dist/server.js:50760:350264)
          at createClass (/home/abhishek/projects/website/dist/server.js:79119:20)
          at createDirectiveInstance (/home/abhishek/projects/website/dist/server.js:78988:20)
          at createViewNodes (/home/abhishek/projects/website/dist/server.js:87348:36)
          at createRootView (/home/abhishek/projects/website/dist/server.js:87262:5)
          at Object.createProdRootView [as createRootView] (/home/abhishek/projects/website/dist/server.js:87774:12)
          at ComponentFactory_.create (/home/abhishek/projects/website/dist/server.js:78467:29)
          at RouterOutlet.activateWith (/home/abhishek/projects/website/dist/server.js:183250:40)
    },
    scheduleFn: undefined,
    cancelFn: undefined,
    callback: [Function],
    invoke: [Function]

`

I need to define google with a valid value in server.ts to avoid this error. Any turn around to import google at node level will be helpful. Is there any package or module which can help me

0 Answers
Related