Adam Szymański
Adam Szymański

Reputation: 365

Firebase Functions v.9 - Internal Error after using connectFunctionsEmulator()

I'm trying to setup Emulator for my firebase functions but I receive this annoying internal error. Let's begin with code.

  const requestApi = () => {
    const functions = getFunctions(app);
    connectFunctionsEmulator(functions, "127.0.0.1", 5001);
    const helloWorld = httpsCallable(functions, "helloWorld");
    helloWorld()
      .then((result) => {
        console.log(result);
      })
      .catch((error) => {
        console.log(error.message, error.code, error.details);
      });
  };

So this function works great, except when I add connectFunctionsEmulator(functions, "127.0.0.1", 5001); to it.

The catch block logs only this useless message.

internal functions/internal undefined

I also receive warning about Timer.

Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info. (Saw setTimeout with duration 70000ms)

That's all. Pretty strange, isn't it :/ ?

-- Cloud Function

exports.helloWorld = functions.https.onRequest(async (req, res) => {
  res.json({ result: `Check` });
});

I add this here cause someone can be curious about this. But, as I mentioned before, function work great when it's deployed. I'm almost sure that it's client side issue.

I receive this error no matter what host or port has been provided. Error is thrown even when Emulator is off.

Upvotes: 1

Views: 837

Answers (1)

Adam Szymański
Adam Szymański

Reputation: 365

Ok, so after almost a week of fighting with this sh!t.

When you use Expo Go like me. You should copy the host address on which you are emulating your app, and use the same address you emulate your functions (or other tools).

enter image description here

app.json

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "emulators": {
    "functions": {
      "host": "192.168.0.104",
      "port": 5001
    }
  }
}

and final code of requestApi function

const requestApi = async () => {
    const functions = getFunctions(app);

    connectFunctionsEmulator(functions, "192.168.0.104", 5001);   <--- ADDRESS!!!

    const helloWorld = httpsCallable(functions, "helloWorld");
    helloWorld()
      .then((result) => {
        console.log(result);
      })
      .catch((error) => {
        console.log(error.message, error.code, error.details);
      });
  };

Upvotes: 5

Related Questions