I am developing a React Native app using Expo SDK 43 and Firebase 9.6.1, and my app can't call cloud functions running locally in the FB emulator. It can successfully call cloud functions if I deploy them to production, verified by checking the FB logs. Here's the relevant code:
import { initializeApp } from 'firebase/app';
import { connectFunctionsEmulator, getFunctions, httpsCallable } from 'firebase/functions';
import Constants from 'expo-constants';
import firebaseConfig from './firebaseConfig';
const app = initializeApp(firebaseConfig);
const functions = getFunctions(app);
const host = `http://${Constants.manifest.debuggerHost.split(':')[0]}`;
const port = 5001;
connectFunctionsEmulator(functions, host, port);
const helloWorld = httpsCallable(functions, 'helloWorld');
helloWorld();
The console shows:
[Unhandled promise rejection: FirebaseError: internal]
at http://192.168.1.166:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:173824:321 in _createSuperInternal
at node_modules/@firebase/util/dist/index.esm2017.js:538:139 in createMockUserToken
at http://192.168.1.166:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:188248:321 in _createSuperInternal
at node_modules/@firebase/auth/dist/rn/phone-1d904137.js:7922:16 in tslib.__generator$argument_1
at node_modules/@firebase/auth/dist/rn/phone-1d904137.js:7995:0 in <global>
at http://192.168.1.166:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:188924:37 in call$
It's getting the right IP address and port, and, in fact, I can visit the URL in the browser (http://192.168.1.166:5001/MY-PROJECT/us-central1/helloWorld) and see that it's being called in the FB emulator UI. I just can't get the app to do it.
I've been able to use the function emulator before with an older Expo SDK and FB 8, but I'd prefer to stick with what I've got.
Here's the code for the actual cloud function, although I don't think it matters:
import * as functions from 'firebase-functions';
export const helloWorld = functions.https.onCall((data, context) => {
console.log('something ran');
console.log(data);
return data;
});