Search code examples
angularfirebaseangularfire2

AngularFireFunctions injection error when building with --prod flag


I am using AngularFireFunctions in a modal and it works fine in development but now that I have compiled using the --prod flag I get the error below.

I have determined it is due to the '"optimization": true' setting in the angular.json file and the use of a modal. If I set this to false it works and I have another project that it is working fine but I can't determine the difference.
I tried creating a new Angular 8 project from scratch with the latest versions of everything and I get the exact same issue.

If I remove "private functions: AngularFireFunctions" from the constructor it does not have the error.

Here is the error:

ERROR Error: Uncaught (in promise): TypeError: StaticInjectorError[n -> t]: 
  Object(...)(...).functions is not a function
TypeError: StaticInjectorError[n -> t]: 
  Object(...)(...).functions is not a function
    at functions.js:25
    at e.invoke (zone.js:391)
    at t.run (zone.js:150)
    at t.runOutsideAngular (core.js:17258)
    at new t (functions.js:23)
    at core.js:21273
    at Bc (core.js:21235)
    at Vc (core.js:21199)
    at t.get (core.js:21907)
    at core.js:9141
    at j (zone.js:831)
    at zone.js:741
    at a (tslib.es6.js:68)
    at e.invoke (zone.js:391)
    at Object.onInvoke (core.js:17299)
    at e.invoke (zone.js:390)
    at t.run (zone.js:150)
    at zone.js:889
    at e.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17290)

Here is the modal code:

export class ElementsComponent implements OnInit {
  @Input() amount: number;
  @Input() description: string;
  @Input() hasDefaultSource: boolean;
  @ViewChild('cardNumberElement') cardNumberElement: ElementRef;
  @ViewChild('cardExpiryElement') cardExpiryElement: ElementRef;
  @ViewChild('cardCvcElement') cardCvcElement: ElementRef;
  useAsDefaultSource = true;

  stripe; // : stripe.Stripe;
  card;
  cardNumber;
  cardExpiry;
  cardCvc;
  cardNumberErrors;
  cardExpiryErrors;
  cardCvcErrors;
  cardErrors;
  confirmation;

  constructor(private auth: AuthService,
              private functions: AngularFireFunctions,
              public modal: NgbActiveModal,
              private spinner: NgxSpinnerService) {}

App.module.ts:

import { AngularFireFunctions } from '@angular/fire/functions';
...
providers: [
    AngularFireFunctions,
...

Solution

  • My mistake. Should be:

    import { AngularFireFunctionsModule } from '@angular/fire/functions'; ... imports: [ AngularFireFunctionsModule, ...