Skip to content

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

Closed

Description

@sunwupark

[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 ([email protected])
[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

Activity

  1. saitogo555 commented on May 24, 2023

    @saitogo555

    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.

  2. blidd-google commented on May 25, 2023

    @blidd-google
    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.

  3. self-assigned this
    on May 25, 2023
  4. added
    Needs: Author Feedback
    and removed on May 25, 2023
  5. thandal commented on May 26, 2023

    @thandal

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

  6. hamzahoda commented on May 28, 2023

    @hamzahoda

    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

  7. qeema commented on May 30, 2023

    @qeema

    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.

  8. google-oss-bot commented on Jun 8, 2023

    @google-oss-bot
    Collaborator

    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!

  9. google-oss-bot commented on Jun 13, 2023

    @google-oss-bot
    Collaborator

    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.

  10. 80 remaining items

  11. agustinFeijoo commented on Nov 11, 2024

    @agustinFeijoo

    Same issue

  12. dsl101 commented on Nov 27, 2024

    @dsl101

    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",
    
  13. rubenheymans commented on Dec 1, 2024

    @rubenheymans

    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?

  14. dsl101 commented on Dec 2, 2024

    @dsl101

    Well, for me, the error goes away :)

  15. dsl101 commented on Dec 4, 2024

    @dsl101

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

  16. HunderlineK commented on Dec 29, 2024

    @HunderlineK

    This is also happening, locally and also on IDX - it's such a non-descriptive error

  17. saurabhchalke commented on Dec 30, 2024

    @saurabhchalke

    Thanks for the suggestion! @dsl101
    It works for my by adding the following env variable while running the function deploy command: FUNCTIONS_DISCOVERY_TIMEOUT=60

  18. shahbaz-khan-hub commented on Jan 31, 2025

    @shahbaz-khan-hub

    make sure you have installed firebase tools locally in the project to check run npm list firebse-tools if you see something like another directory not your project directory it means you have not installed firebase tools locally in the project

  19. carloslfu commented on Apr 1, 2025

    @carloslfu

    For people trying to deploy Python functions, you need to add a requirements.txt in the source dir. Same for Node, you need a package.json in the source dir.

    Image

    This is the code responsible for that:

    logger.debug("Customer code is not Python code.");

  20. Saddamdev0 commented on Apr 23, 2025

    @Saddamdev0

    Hey when I faced this issue I looked there were node modules unnecessarily installed in my functions folder so I just deleted them, also make sure you dont have any firebase-functions installed in functions, take a look at package.json if there is any firebase-functions then within the same directory run npm uninstall firebase-functions.

  21. madmacc commented on Apr 23, 2025

    @madmacc

    For me this does not occur if I stay on the window (Keep it in focus) while deploying functions.
    If I start the deploy then leave the window I will get this error and have to run it a second time for it to work.
    It is also affected by my local backup software running.
    I believe may be to do with resources on my local computer. My machine is kind of old.

  22. nfairfield commented on Apr 30, 2025

    @nfairfield

    My 2c: I always have to run firebase command-lines twice. The first time, I get this error. The second time (and subsequent), it works just fine (even if its from two different powershell instances). I mention this because I fear that some of the solutions above... are really just people trying different things multiple times, and eventually it works.

    It seems to be some sort of credential/caching issue, but I've never been able to track it down.

  23. dsl101 commented on May 1, 2025

    @dsl101

    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",
    

    Have you tried this solution and it doesn't work? What values for the timeout have you experimented with? Providing more data would be really helpful...

  24. depikaguptaa commented on Jul 2, 2025

    @depikaguptaa

    Downgrading to previous version worked for me!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions