firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.03k stars 204 forks source link

Callable functions not found when testing on Emulator #1627

Open PabloMzGa opened 1 month ago

PabloMzGa commented 1 month ago

Related issues

I haven't found any related issues.

[REQUIRED] Version info

Node version: v18.19.1

firebase-functions: 6.0.1

firebase-tools: 13.22.0

firebase-admin: 12.1.0

[REQUIRED] Test case

I am using a test code based on the docs. I have tested with the quickstart repo getting the same results: Link.

Here is my code:

index.ts (inside the "functions" folder)

import { onCall } from "firebase-functions/v2/https";
exports.test = onCall((request) => {
    console.log("Recibida llamada");
    return { message: "Hello from Firebase!" };
  });`

test.ts (outside of functions folder)

import { initializeApp } from "firebase/app";
import { getFunctions, httpsCallable, connectFunctionsEmulator } from "firebase/functions";

// Firease config
const firebaseConfig = {
  projectId: "demo-project",
  storageBucket: "demo-project.appspot.com",
  messagingSenderId: "123456789",
  appId: "1:123456789:web:abcdef",
};

// Firebase init
const app = initializeApp(firebaseConfig);

// Get functions ref
const functions = getFunctions(app);

// Connect with emulator
connectFunctionsEmulator(functions, "127.0.0.1", 5001);

// Call function
const myFunction = httpsCallable(functions, 'test');

myFunction({ some: 'data' })
  .then((result) => {
    console.log(result.data);
  })
  .catch((error) => {
    console.error("Error calling function:", error);
  });

[REQUIRED] Steps to reproduce

[REQUIRED] Expected behavior

It should connect with the emulator and return the promise from the function and execute it correctly.

[REQUIRED] Actual behavior

I get an error with the promise. This is my console log:

Error calling function: [FirebaseError: not-found] { code: 'functions/not-found', customData: undefined, details: undefined }

I know it's connecting to the emulator because when I change the port or the ip, i get internal-error instead. Also the deployment on the emulator it's correct because it appears on the log. It works correctly when called from firebase functions:shell.

Were you able to successfully deploy your functions?

I am not testing deployment since I need this just for testing.

google-oss-bot commented 1 month ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.