Search code examples
angularionic-frameworkgoogle-cloud-functionsangularfire

Firebase Callable Function works on one project, throws Error on the other


I get ERROR Error: internal on my Ionic-Angular app (in the Chrome DevTool) after calling a basic callable Firebase cloud function. My app is running locally using the ionic serve command.

  • The cloud function is as follows:
import * as functions from "firebase-functions";

export const helloWorld = functions
  .region("europe-west2")
  .https.onCall((data, context) => {
    functions.logger.info("Hello logs!", { structuredData: true });
    return "Hello from Firebase!";
  });
  • I call the function from my app in the following way:
this.AngularFireFunctions
        .httpsCallable("helloWorld")({})
        .toPromise()
        .then((r) => console.log(r));
  • The full error that appears in my Chrome DevTool log is as follows:
app.component.ts:46 Error: internal
    at new HttpsErrorImpl (index.cjs.js:60)
    at _errorForResponse (index.cjs.js:155)
    at Service.<anonymous> (index.cjs.js:560)
    at step (tslib.es6.js:100)
    at Object.next (tslib.es6.js:81)
    at fulfilled (tslib.es6.js:71)
    at ZoneDelegate.invoke (zone-evergreen.js:368)
    at Zone.run (zone-evergreen.js:130)
    at zone-evergreen.js:1272
    at ZoneDelegate.invokeTask (zone-evergreen.js:402)

To pinpoint the issue, I tried running the same thing on this other Ionic-Angular project of mine. I did so in exactly the same way (same code as above), in exactly the same location (app.component.ts), with the same version of AngularFire (^6.0.2), and ran in the same way (using ionic serve) but it ended up working on that second project!

Firebase logs comparison

  • No logs appear on Firebase when I call the function from the first project (a.k.a. when I get the error).
  • I get logs of normal functioning when called from the second project (a.k.a. when it is successful). There are two, which are as follows: Hello logs! {"structuredData":true}, and Function execution took 4 ms, finished with status code: 200 .

I tried going through the same process for another cloud function, and regardless of the function I call, the same thing happens: I get error internal on that first project, and the function is called successfully on that second project.

I'm assuming that means the error can't be server-side, nor in the way I make the call, but then what is it? I'm clueless as where to even look now! What else comes into play and could cause this issue? Could something be interfering with the process? Any help, hints or advises would be greatly appreciated!

UPDATE

My co-worker pulled my version of the first project from GitHub, and the cloud function ran correctly without throwing Error: Internal! Could my project be corrupted or something?


Solution

  • I finally got to the end of this problem!

    I had to delete both my /node_modules folder and package-lock.json file (/dist would also be a good idea, but I didn't have one), and then run npm install to reinstall all dependencies and rebuild the package-lock.json folder.

    What I would do in the past was only delete the /node_modules folder, which, as I understand it now, left package-lock.json untouched and installing older versions of dependencies, creating conflicts and hence this ERROR: internal.