When I run my angular application with ng serve it works. However when I am deploying (either Jboss or Tomcat Servers) same angular application it gives following at console:
Uncaught ReferenceError: Cannot access 'GA' before initialization
at main-es2015.faddfe3f773581d6c95a.js:1
at Module.zUnb (main-es2015.faddfe3f773581d6c95a.js:1)
at l (runtime-es2015.c5fa8325f89fc516600b.js:1)
at Object.0 (main-es2015.faddfe3f773581d6c95a.js:1)
at l (runtime-es2015.c5fa8325f89fc516600b.js:1)
at t (runtime-es2015.c5fa8325f89fc516600b.js:1)
at Array.r [as push] (runtime-es2015.c5fa8325f89fc516600b.js:1)
at main-es2015.faddfe3f773581d6c95a.js:1
I have used ng build --prod ---base-href=myapp
to build my module.
What could've possibly gone wrong?
Optional:
I have already tried "emitDecoratorMetadata": false
based on a solution on another thread. But still issue persists.
For this problem, I have figured out this was due to some compilation from the typescript to the javascript issue. I have managed to fix this by a workaround just by initializing GA (please note this GA is dynamically changing with each build compilation) at javascript manually after ng build. And it fixed.
A similar issue has been discussed at Gitlab forum.
further explaining my solution:
var GA; // manually declared initializing here.
return e.ngInjectableDef=ue({factory:function(){return new GA},token:GA,providedIn:"root"})