Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callable functions not found when testing on Emulator #1627

Open
PabloMzGa opened this issue Oct 17, 2024 · 1 comment
Open

Callable functions not found when testing on Emulator #1627

PabloMzGa opened this issue Oct 17, 2024 · 1 comment

Comments

@PabloMzGa
Copy link

PabloMzGa commented Oct 17, 2024

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

  • Set up functions project
  • Import code
  • Install dependencies and set up emulator with "firebase emulators:start --project demo-test"
  • Execute "test.js"

[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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants