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

Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification #5888

Closed
sunwupark opened this issue May 24, 2023 · 91 comments

Comments

@sunwupark
Copy link

sunwupark commented May 24, 2023

[REQUIRED] Environment info

firebase-tools:
firebase-tools: 12.1.0
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1"
"firebase-functions-test": "^3.1.0"

image

image

**Platform: Windows wsl (Ubuntu)
Node: v18.16.0
Python: v3.10.6
openjdk: v"11.0.19"

[REQUIRED] Test case

i have followed the exact steps in
https://firebase.google.com/docs/functions/get-started?gen=2nd&hl=ko#about_this_tutorial

[REQUIRED] Expected behavior

No error should have occured

[REQUIRED] Actual behavior

When I run firebase emulators:start

i emulators: Starting emulators: functions, firestore
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, hosting, pubsub, storage
i firestore: Firestore Emulator logging to firestore-debug.log
✔ firestore: Firestore Emulator UI websocket is running on
9150.
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "/mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/functions" for Cloud Functions...
✔ functions: Using node@18 from host.
⬢ functions: Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine
backend specification

┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://127.0.0.1:4000/

└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI

├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore
└───────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at 127.0.0.1:4400
Other reserved ports: 4500, 9150

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

image

When I run firebase emulators:start --debug

firebase emulators:start --debug
[2023-05-24T00:10:55.555Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2023-05-24T00:10:55.556Z] > authorizing via signed-in user (sunwu5678@gmail.com)
[2023-05-24T00:10:55.604Z] openjdk version "11.0.19" 2023-04-18
OpenJDK Runtime Environment (build 11.0.19+7-post-Ubuntu-0ubuntu122.04.1)

[2023-05-24T00:10:55.605Z] OpenJDK 64-Bit Server VM (build 11.0.19+7-post-Ubuntu-0ubuntu122.04.1, mixed mode, sharing)

[2023-05-24T00:10:55.608Z] Parsed Java major version: 11
i emulators: Starting emulators: functions, firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: functions, firestore"}}
[2023-05-24T00:10:55.614Z] assigned listening specs for emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"firestore":[{"address":"127.0.0.1","family":"IPv4","port":8080}],"firestore.websocket":[{"address":"127.0.0.1","family":"IPv4","port":9150}]},"metadata":{"message":"assigned listening specs for emulators"}}
[2023-05-24T00:10:55.620Z] [hub] writing locator at /tmp/hub-nodejs-a4db9.json
[2023-05-24T00:10:55.625Z] late-assigned ports for functions and eventarc emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"firestore":[{"address":"127.0.0.1","family":"IPv4","port":8080}],"firestore.websocket":[{"address":"127.0.0.1","family":"IPv4","port":9150}],"functions":[{"address":"127.0.0.1","family":"IPv4","port":5001}],"eventarc":[{"address":"127.0.0.1","family":"IPv4","port":9299}]},"metadata":{"message":"late-assigned ports for functions and eventarc emulators"}}
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, hosting, pubsub, storage {"metadata":{"emulator":{"name":"functions"},"message":"The following emulators are not running, calls to these services from the Functions emulator will affect production: \u001b[1mauth, database, hosting, pubsub, storage\u001b[22m"}}
[2023-05-24T00:10:55.627Z] defaultcredentials: writing to file /home/sunwu/.config/firebase/sunwu5678_gmail_com_application_default_credentials.json
[2023-05-24T00:10:55.628Z] Setting GAC to /home/sunwu/.config/firebase/sunwu5678_gmail_com_application_default_credentials.json {"metadata":{"emulator":{"name":"functions"},"message":"Setting GAC to /home/sunwu/.config/firebase/sunwu5678_gmail_com_application_default_credentials.json"}}
[2023-05-24T00:10:55.631Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/nodejs-a4db9/adminSdkConfig [none]
[2023-05-24T00:10:56.042Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/nodejs-a4db9/adminSdkConfig 200
[2023-05-24T00:10:56.042Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/nodejs-a4db9/adminSdkConfig {"projectId":"nodejs-a4db9","storageBucket":"nodejs-a4db9.appspot.com"}
[2023-05-24T00:10:56.077Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}
[2023-05-24T00:10:56.077Z] Ignoring unsupported arg: single_project_mode_error {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: single_project_mode_error"}}
[2023-05-24T00:10:56.077Z] Starting Firestore Emulator with command {"binary":"java","args":["-Djava.net.preferIPv4Stack=true","-Dgoogle.cloud_firestore.debug_log_level=FINE","-Duser.language=en","-jar","/home/sunwu/.cache/firebase/emulators/cloud-firestore-emulator-v1.17.4.jar","--host","127.0.0.1","--port",8080,"--websocket_port",9150,"--project_id","nodejs-a4db9","--rules","/mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/firestore.rules","--single_project_mode",true,"--functions_emulator","127.0.0.1:5001"],"optionalArgs":["port","webchannel_port","host","rules","websocket_port","functions_emulator","seed_from_export","project_id","single_project_mode"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {"binary":"java","args":["-Djava.net.preferIPv4Stack=true","-Dgoogle.cloud_firestore.debug_log_level=FINE","-Duser.language=en","-jar","/home/sunwu/.cache/firebase/emulators/cloud-firestore-emulator-v1.17.4.jar","--host","127.0.0.1","--port",8080,"--websocket_port",9150,"--project_id","nodejs-a4db9","--rules","/mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/firestore.rules","--single_project_mode",true,"--functions_emulator","127.0.0.1:5001"],"optionalArgs":["port","webchannel_port","host","rules","websocket_port","functions_emulator","seed_from_export","project_id","single_project_mode"],"joinArgs":false}"}}
i firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
[2023-05-24T00:10:57.195Z] May 24, 2023 9:10:57 AM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://127.0.0.1:9150
{"metadata":{"emulator":{"name":"firestore"},"message":"May 24, 2023 9:10:57 AM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start\nINFO: Started WebSocket server on ws://127.0.0.1:9150\n"}}
[2023-05-24T00:10:57.291Z] API endpoint: http://127.0.0.1:8080
{"metadata":{"emulator":{"name":"firestore"},"message":"API endpoint: http://127.0.0.1:8080\n"}}
[2023-05-24T00:10:57.292Z] If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080

Dev App Server is now running.

{"metadata":{"emulator":{"name":"firestore"},"message":"If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:\n\n export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080\n\nDev App Server is now running.\n\n"}}
✔ firestore: Firestore Emulator UI websocket is running on 9150. {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator UI websocket is running on 9150."}}
[2023-05-24T00:10:57.362Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}
[2023-05-24T00:10:57.363Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}
[2023-05-24T00:10:57.364Z] Starting Emulator UI with command {"binary":"node","args":["/home/sunwu/.cache/firebase/emulators/ui-v1.11.6/server/server.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {"binary":"node","args":["/home/sunwu/.cache/firebase/emulators/ui-v1.11.6/server/server.js"],"optionalArgs":[],"joinArgs":false}"}}
i ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \u001b[1mui-debug.log\u001b[22m"}}
[2023-05-24T00:10:57.486Z] Web / API server started at 127.0.0.1:4000
{"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at 127.0.0.1:4000\n"}}
i functions: Watching "/mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/functions" for Cloud Functions... {"metadata":{"emulator":{"name":"functions"},"message":"Watching "/mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/functions" for Cloud Functions..."}}
[2023-05-24T00:10:57.657Z] Validating nodejs source
[2023-05-24T00:10:58.198Z] > [functions] package.json contents: {
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0"
},
"private": true
}
[2023-05-24T00:10:58.203Z] Building nodejs source
[2023-05-24T00:10:58.204Z] Failed to find version of module node: reached end of search path /mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/functions/node_modules
✔ functions: Using node@18 from host.
[2023-05-24T00:10:58.215Z] Could not find functions.yaml. Must use http discovery
[2023-05-24T00:10:58.240Z] Found firebase-functions binary at '/mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/functions/node_modules/.bin/firebase-functions'
[2023-05-24T00:11:02.712Z] Serving at port 8528

[2023-05-24T00:11:16.857Z] shutdown requested via /__/quitquitquit

⬢ functions: Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification {"metadata":{"emulator":{"name":"functions"},"message":"Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification"}}

┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://127.0.0.1:4000/
└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore
└───────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at 127.0.0.1:4400
Other reserved ports: 4500, 9150

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files

My project Structure
image

@saitogo555
Copy link

saitogo555 commented May 24, 2023

I had the same error in almost the same environment as you.
I don't know the exact cause, but I have found that the problem is caused by firebase-tools.
I downgraded the firebase-tools version to 11.29.1 and it works fine.
Also, version 12.2.0 has now been released, so maybe the latest version will work.

@blidd-google
Copy link
Contributor

Hi @sunwupark, thanks for reporting this error. From the details you provided, it's difficult to diagnose the underlying issue causing your functions code to not load. Could you provide your source code, or a simple example that I could use to reproduce your issue? Thanks.

@blidd-google blidd-google self-assigned this May 25, 2023
@blidd-google blidd-google added Needs: Author Feedback Issues awaiting author feedback type: support and removed type: bug labels May 25, 2023
@thandal
Copy link

thandal commented May 26, 2023

I had the same problem, downgrading also worked for me -- thanks @saitogo555 !

@hamzahoda
Copy link

Got the same error

Error: User code failed to load. Cannot determine backend specification.

Turns out that when I initialized a new project using Firebase init the default nodejs version it uses is 18.

Just needed to change my version in the package.json file to the current one installed on my system. For me, it was 16.

"engines": { "node": "16" },

firebase31
firebase32

@qeema
Copy link

qeema commented May 30, 2023

We had same problem when we use wsl and mnt folder(local windows).
But, using only wsl(folder is on wsl ubuntu not "/mnt" directory) was worked.

@google-oss-bot
Copy link
Contributor

Hey @sunwupark. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@sunwupark if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@hamen
Copy link

hamen commented Jun 19, 2023

I'm trying a very basic function and it's failing while deploying.

My project is on the Windows partition, while I'm deploying from WSL2 terminal.

I was using the latest firebase-tools. I removed them:

npm remove -g firebase-tools

and I installed a previous version

npm install -g firebase-tools@11.29.1

as suggested by @sunwupark 🎊

image

@Sahmuraii
Copy link

We had same problem when we use wsl and mnt folder(local windows). But, using only wsl(folder is on wsl ubuntu not "/mnt" directory) was worked.

How did you end up fixing it using this issue? Since the folder I'm trying to access is going through /mnt/c/Users/...

@takahashi-shotaro-al
Copy link

In my case, I run the deploy twice and it succeeds.

@thirstycoda
Copy link

Downgrading also worked for me

@danielbraghini
Copy link

danielbraghini commented Jul 1, 2023

In my case, I run the deploy twice and it succeeds too, but eventually it happens again and I need to deploy a or serve a second time to works. So, maybe there is a problem with de latest version

@Zujaj
Copy link

Zujaj commented Jul 6, 2023

It's sad to disclose here that even using the latest Firebase tools version 12.4.2 had no effect! The error Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification kept on rising, tried it with cmd, PowerShell & Git bash but no luck. Instead, I had to downgrade to version 11.29.1 as mentioned by @hamen just to execute the firebase functions npm run serve and it currently works.

scripts:
{
  "serve": "npm run build && firebase emulators:start --only functions",
},
"engines": {
    "node": "16"
 },

I am using Node Version Manager, my node version is v16.20.0 & npm version is 9.6.7.

A humble request to the team to please resolve this error on high priority.

@tarpagad
Copy link

In my case, I run the deploy twice and it succeeds.

I started having the issue after cloning my disc onto a new one. Now whether it's to run firebase serve --only functions or any other cmd, I have to do it TWICE

@rubenheymans
Copy link

rubenheymans commented Jul 14, 2023

same problem here using "firebase-tools": "^12.4.0", I start the emulators and I get this error, then I ctrl +c and start the emulators again. The error is gone. This issue should be re-opened
@google-oss-bot Please reopen this issue.

@rendomnet
Copy link

Same bug here

@jheyer159
Copy link

Experiencing this intermittently while developing with python.

Seems the only solution we have found, haven't tried downgrading, is removing the functions folder, and Firebase config, and re-initing which will resolve it, but is not a good solution.

@saitogo555
Copy link

As I already posted at the beginning of the thread, downgrading the firebase-tools version to 11.29.1 works fine. if you still get the error after trying with 11.29.1, we can all work out a solution.

@Zujaj
Copy link

Zujaj commented Jul 17, 2023

As I already posted at the beginning of the thread, downgrading the firebase-tools version to 11.29.1 works fine. if you still get the error after trying with 11.29.1, we can all work out a solution.

Downgrading isn't quite a proper solution, it can be a workaround. By downgrading, we are missing all the latest features, commands & bug fixes that are being introduced with the release of the new Firebase tools CLI.

@takahashi-shotaro-al
Copy link

takahashi-shotaro-al commented Jul 18, 2023

related #5834

@Zujaj
Copy link

Zujaj commented Jul 19, 2023

Thanks for sharing this. I am currently using Firebase CLI version 12.4.4 & applied the below steps. It seems to be working at least after failing once (sometimes).

P.S. I know it's not right to manipulate the JS build code, but I couldn't find any other option. These steps have been created by observing #5834 file changes

  1. Visit the folder %AppData%\npm\node_modules\firebase-tools\lib\deploy\functions\runtimes\discovery.
    (%AppData% refers to C:\Users\My-User\AppData\Roaming in Windows Operating System)

  2. Open the index.js file with VSCode or Notepad & search for async function detectFromPort(port, project, runtime, timeout

  3. Replace the default timeout (10 seconds) with 50 seconds as shown below:

    • Before ➡ async function detectFromPort(port, project, runtime, timeout = 10000 //10 seconds
    • After ➡ async function detectFromPort(port, project, runtime, timeout = 50000 //50 seconds
  4. Save the file.

A friendly suggestion for @takahashi-shotaro is that you could upgrade your current Pull Request branch & re-submit the code. Maybe the Firebase team would reconsider looking into it.

@marco-mastella
Copy link

So much time wasted for a ... timeout (working with docker / devcontainer / WSL2)

@jeanmatthieud now there is the solution...
to increase timeout for deploy functions
add FUNCTIONS_DISCOVERY_TIMEOUT=50 (50 are seconds, you can increase ) to environmental variables

you can find the fix on node_modules\firebase-tools\lib\deploy\functions\runtimes\discovery>
index.js
...
const TIMEOUT_OVERRIDE_ENV_VAR = "FUNCTIONS_DISCOVERY_TIMEOUT";
...
const timedOut = new Promise((resolve, reject) => {
setTimeout(() => {
reject(new error_1.FirebaseError("User code failed to load. Cannot determine backend specification"));
}, +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000 || timeout);
});

@jeanmatthieud
Copy link

So much time wasted for a ... timeout (working with docker / devcontainer / WSL2)

@jeanmatthieud now there is the solution... to increase timeout for deploy functions add FUNCTIONS_DISCOVERY_TIMEOUT=50 (50 are seconds, you can increase ) to environmental variables

you can find the fix on node_modules\firebase-tools\lib\deploy\functions\runtimes\discovery> index.js ... const TIMEOUT_OVERRIDE_ENV_VAR = "FUNCTIONS_DISCOVERY_TIMEOUT"; ... const timedOut = new Promise((resolve, reject) => { setTimeout(() => { reject(new error_1.FirebaseError("User code failed to load. Cannot determine backend specification")); }, +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000 || timeout); });

Yes, I know but finding this GitHub issue took me so much time (I believed that my code was the issue, as it didn't appeared at first, when the project was smaller).
It should be better documented, or the error message should warn that it could be a timeout issue, and how change the timeout value.

@Dagmawi-a-Negatu
Copy link

Downgrading firebase tools version and chancing the runt time for functions to nodejs 16 seemed to fix my issue.

@PongphonTan
Copy link

marco-mastella's method to add FUNCTIONS_DISCOVERY_TIMEOUT=50 (50 are seconds, you can increase) to environmental variables work for firebase-tools 13.15.0 and Python 3.10.11 on Windows 11

@ybakhshi
Copy link

ybakhshi commented Aug 6, 2024

I had the same issue but after I installed the same version of firebase-cli that i have in my project, it is resolved!

@Umer-309
Copy link

I was having the same issue.
"firebase-tools": "13.15.0"
"firebase-admin": "^12.1.0",
"firebase-functions": "^5.0.0"

I searched through internet and spent hours finding a fix for this at last @tarpagad's solution worked for me.
Thanks man!

In my case, I run the deploy twice and it succeeds.

I started having the issue after cloning my disc onto a new one. Now whether it's to run firebase serve --only functions or any other cmd, I have to do it TWICE

@firebase-ops team should resolve this issue on high priority because it's wasting dev time.

@johndunderhill
Copy link

@Umer-309 did you see #7176?

@Umer-309
Copy link

Umer-309 commented Aug 13, 2024 via email

@KishorJena
Copy link

for me upgrading firebase-tool to latest 13.15.4 solved the issue.

@chrisdev3001
Copy link

dear god... I have spent 2 hours with this issue :(

npm install -g firebase-tools 

its worked for me

@madmacc
Copy link

madmacc commented Sep 8, 2024

I get this about 50% of the time. I find just retrying resolves it.

@imanabu
Copy link

imanabu commented Sep 11, 2024

10 September 2024

  • This still is happening and sporadically with
 firebase --version
13.16.0

I have observed that,

  1. Sometimes this fixes itself via firebase --reauth
  2. Sometimes this fixes by closing the shell and running the full login to gcloud and firebase use <alias>
  3. It does happen often when I from one FB project to another, e.g., from stating to production back to production
  4. It does not happen with host deployment, only with functions deployment

I do not have any real idea, as it does work some of the time and not the other time, and deployed functions are working fine so I seriously doubt it has anything to do with my own Typescript based functions.

@LucasJoelMcG
Copy link

Had the same issue with firebase-tools v12.6.1 on a Nest.js project.
Updating to v13.17.0 solved the problem.

@HMothaffar
Copy link

Updating firebase-tools from13.15.0 to 13.19.0 fixed the problem

@langhoangal
Copy link

langhoangal commented Oct 11, 2024

Solution in the UPDATE section

I've isolated the problem to the firestore.client() line, when I comment it out deploy goes trough no problem at all, if the code is not commented out deploy fails...

Python function:

import firebase_admin
import stripe
import json
from firebase_functions import https_fn, options
from firebase_admin import firestore
from hexbytes import HexBytes
from scripts.interact import MAT_grantAuthority

# Application Default credentials are automatically created.
app = firebase_admin.initialize_app()
# db = firestore.client()

UPDATE-SOLUTION: Firebase docs tell you to do the following:

import firebase_admin
from firebase_admin import firestore

# Application Default credentials are automatically created.
app = firebase_admin.initialize_app()
db = firestore.client()

This worked while testing the function locally, firebase serve worked no problem at all but when I tried to deploy it, deployment failed with the error: FirebaseError: User code failed to load. Cannot determine backend specification

The solution was to generate private key from firebase project and use it like below:

import firebase_admin
import stripe
import json
from firebase_functions import https_fn, options
from firebase_admin import credentials
from firebase_admin import firestore
from hexbytes import HexBytes
from scripts.interact import MAT_grantAuthority

#THIS SOLVED THE PROBLEM
cred = credentials.Certificate('PATH_TO_YOUR_PRIVATE_KEY_JSON.json')
firebase_admin.initialize_app(cred)

@urosran
Thank you! The only solution that work for me. I'm wrote the code using python also.

@SebastianKumor
Copy link

Still happens in tools 13.22.0 and with python 3.12 functions

@toddlee
Copy link

toddlee commented Oct 26, 2024

Not sure if this could be a hint.. but I've been trying to test cloud functions in local emulator and had the same error. After running firebase emulators:start with --debug option, I see these errors, and one thing that's weird is it says the code is not Node (it is a Node..)

i  functions: Watching "/Users/tlee/Documents/server/scripts/functions" for Cloud Functions... {"metadata":{"emulator":{"name":"functions"},"message":"Watching \"/Users/tlee/Documents/server/scripts/functions\" for Cloud Functions..."}}
[2024-10-26T07:52:40.620Z] Customer code is not Node
[2024-10-26T07:52:40.620Z] Customer code is not Python code.
⬢  functions: Failed to load function definition from source: FirebaseError: Could not detect runtime for functions at /Users/tlee/Documents/server/scripts/functions {"metadata":{"emulator":{"name":"functions"},"message":"Failed to load function definition from source: FirebaseError: Could not detect runtime for functions at /Users/tlee/Documents/server/scripts/functions"}}

Maybe it's somehow not recognizing the js file that has cloud function codes?

@wickedest
Copy link

There is an open issue #7775 in firebase-tools.

@toddlee
Copy link

toddlee commented Oct 27, 2024

By reading the firebase source code, it is looking for package.json from the folder where functions is pointing at. After I copied package.json there, it worked.

So, in my firebase.json

{
  "functions": {
    "source": "functions"
  },
  ...

I had to copy package.json under ./functions/. That made it work.

https://github.com/firebase/firebase-tools/blob/e3b60df1eed0cfdec03839c0743f7413a74498ea/src/deploy/functions/runtimes/node/index.ts#L38C1-L38C72

@KelvinCheng5507
Copy link

It's quite disappointing that Firebase doesn't fix this after all these years.

@rubenheymans
Copy link

updated to the latest firebase version (again), still get the error

@agustinFeijoo
Copy link

Same issue

@EricSamson-Tract
Copy link

Thanks for sharing this. I am currently using Firebase CLI version 12.4.4 & applied the below steps. It seems to be working at least after failing once (sometimes).

P.S. I know it's not right to manipulate the JS build code, but I couldn't find any other option. These steps have been created by observing #5834 file changes

  1. Visit the folder %AppData%\npm\node_modules\firebase-tools\lib\deploy\functions\runtimes\discovery.
    (%AppData% refers to C:\Users\My-User\AppData\Roaming in Windows Operating System)

  2. Open the index.js file with VSCode or Notepad & search for async function detectFromPort(port, project, runtime, timeout

  3. Replace the default timeout (10 seconds) with 50 seconds as shown below:

    • Before ➡ async function detectFromPort(port, project, runtime, timeout = 10000 //10 seconds
    • After ➡ async function detectFromPort(port, project, runtime, timeout = 50000 //50 seconds
  4. Save the file.

A friendly suggestion for @takahashi-shotaro is that you could upgrade your current Pull Request branch & re-submit the code. Maybe the Firebase team would reconsider looking into it.

Still having this issue on 13.27.0, and the above seems to be the only thing that works. Thanks!

@dsl101
Copy link

dsl101 commented Nov 27, 2024

Is the FUNCTIONS_DISCOVERY_TIMEOUT environment variable not working for some? I've had this kind of thing in package.json scripts for ages, and it's solved it completely:

"emu": "cross-env FUNCTIONS_DISCOVERY_TIMEOUT=60 firebase emulators:start",

@rubenheymans
Copy link

Is the FUNCTIONS_DISCOVERY_TIMEOUT environment variable not working for some? I've had this kind of thing in package.json scripts for ages, and it's solved it completely:

"emu": "cross-env FUNCTIONS_DISCOVERY_TIMEOUT=60 firebase emulators:start",

how can you verify this variable is set correctly?

@dsl101
Copy link

dsl101 commented Dec 2, 2024

Well, for me, the error goes away :)

@dsl101
Copy link

dsl101 commented Dec 4, 2024

You 'found' something that was posted back in June and I commented on last week. I swear people just aren't reading this thread...

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