2

I'm fighting with this issue for over 3 days. I have no idea what is happening.

Firebase Functions throws error only when I try to use Emulator. I try to execute this function in useEffect hook. Again, when I call deployed Cloud Functions everything seems fine, unfortunately in case of using Emulator things don't want to go so well.

const resolvePromise = async () => {
      functions.useEmulator("https://0.0.0.0:5001");
      const query = functions.httpsCallable("helloWorld");
      query()
        .then((result) => console.log(result))
        .catch((err) => console.log(err));
    };

I receive this useless (for me) error.

Error: ENOENT: no such file or directory, open 'HttpsErrorImpl@http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at getCodeFrame (Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:1296:18)  
    at Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:1367:24
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:146:24)
    at _next (Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:168:9)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

internal
at HttpsErrorImpl@http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:197178:29 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:197273:29 in _errorForResponse
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:197751:39 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:170357:26 in step
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:170287:21 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:170241:31 in fulfilled
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31526:15 in tryCallOne
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31627:26 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31955:16 in _callTimer
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31994:16 in _callImmediatesPass
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:32211:32 in callImmediates
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3457:34 in __callImmediates
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3236:33 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3440:14 in __guard
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3235:20 in flushedQueue

This is all the text which I can see after visiting

http://192.168.0.104:19000/index.bundle -- https://pastebin.com/ggsCMN0W http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false -- https://pastebin.com/LSeufs8H

It don't make any sense for me. At second address it seems like it's correlated to metro dependency so I updated it, it didn't work.

Any ideas? Thanks in advance :D

Edit 1: All errors are logged at client site, it seems like client can't even call emulator.

Edit 2: I tried to update entire firebase to v.9 aswell as Expo to 44 SKD with react-native to 0.64.3

This is how my Request function looks now:

  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);
      });
  };

I receive only this from catch block :(

internal functions/internal undefined

I also receive warning about Timer after executing that function

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)

It don't work only when I try to use Emulator

Adam Szymański
  • 335
  • 4
  • 17

3 Answers3

1

Couple of potential issues here:

  1. Assuming you're using the latest version of Firebase, functions is actually a method: firebase.functions().useEmulator("localhost", 5001); - Note the () after functions. See docs for more info.
  2. Maybe you've already done this, but have you made sure that the functions emulator is actually running and connectable on port 5001)? Could be useful to test it via Postman or similar.
  3. Make sure you're using the correct IP address for the functions emulator given your setup. 0.0.0.0 probably doesn't map where you want it to... assuming the app is running locally and the functions emulator is too, try 127.0.0.1 or "localhost" ... this answer has more options to troubleshoot.
Tim
  • 2,843
  • 13
  • 25
  • 2
    That's the "latest version of the v8 API", but the API is now up to "v9". If this is a new app, then Adam would be wise to start with using the v9 API as v8 and the "compat" mode have a limited lifespan. – Greg Fenton Jan 30 '22 at 21:54
  • I'll try to update entire Firebase to v.9. Keep fingers crossed for it to work. – Adam Szymański Jan 31 '22 at 09:43
  • Again, no progess... Check Edit 2 – Adam Szymański Feb 01 '22 at 21:34
  • @AdamSzymański - Did you confirm step 2? And are you able to call the emulated function via [firebase shell](https://firebase.google.com/docs/functions/local-shell#serve_functions_using_a_cloud_functions_shell)? – Tim Feb 01 '22 at 22:34
  • I'm able to call a function through Insomnia, I receive an error no matter what port I provide. You can also check the most recent question on my profile because I've changed most of things in my code. It also should be more clear. – Adam Szymański Feb 01 '22 at 22:51
0

I am not sure if it is your case, but I had a function:

exports.findUserInAuth = functions.https.onCall((data, context) => {
  let field = data.field;
  let value = data.value;

  if (!field || !value) {
    return false;
  }

  if (field === "email") {
    return admin.auth().getUserByEmail(value);
  }
});

This one returns a promise, I had to change it to wait for the result before doing a return and problem solved...

exports.findUserInAuth = functions.https.onCall((data, context) => {
  let field = data.field;
  let value = data.value;

  if (!field || !value) {
    return false;
  }

  if (field === "email") {
    admin.auth().getUserByEmail(value).then((result) => {
        return result;
      })
      .catch((error) => {
        if (error.code === "auth/user-not-found") {
          return "Email or Password is incorrect";
        }

        return `${error.code} ${error.message}`;
      });
  }

  return false;
});
Eduardo
  • 1,781
  • 3
  • 26
  • 61
0

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 = firebase.functions()

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

    const helloWorld = functions.httpsCallable("helloWorld");
    helloWorld()
      .then((result) => {
        console.log(result);
      })
      .catch((error) => {
        console.log(error.message, error.code, error.details);
      });
  };
Adam Szymański
  • 335
  • 4
  • 17