Repository navigation
Description
[REQUIRED] Environment info
firebase-tools: 12.4.8
Platform: Windows 11 (all updates applied), Node v16.13.0
[REQUIRED] Test case
Sorry, I'm unable to provide an MCVE.
[REQUIRED] Steps to reproduce
Note: This issue is occurring intermittently over the last few days.
Running either firebase deploy or firebase emulators:start results in either the deploy failing or the functions emulators doesn't start, or sometime not all functions are available. Error reported by the CLI is:
!! functions: Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification
However, re-running the command again and it usually works ok on the second attempt.
[REQUIRED] Expected behavior
All functions run in the emulator or the deploy doesn't fail on first attempt.
[REQUIRED] Actual behavior
I've attached the full log for a failed emulator startup, as that's the only one I've been able to capture today, but this may be the relevant section:
[2023-08-21T12:33:42.975Z] > [functions] package.json contents: {
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"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": "16"
},
"main": "index.js",
"dependencies": {
"atlassian-jwt": "^2.0.2",
"dayjs": "^1.11.7",
"express-validator": "^6.15.0",
"firebase-admin": "^11.10.1",
"firebase-functions": "^4.4.1",
"nanoid": "^3.3.4",
"node-forge": "^1.3.1"
},
"devDependencies": {
"eslint": "^8.36.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-promise": "^6.1.1"
},
"private": true
}
[2023-08-21T12:33:42.977Z] Building nodejs source
[2023-08-21T12:33:42.978Z] Failed to find version of module node: reached end of search path C:\Users\MYUSERNAME\documents\my-app\functions\node_modules
- functions: Using node@16 from host.
[2023-08-21T12:33:42.986Z] Could not find functions.yaml. Must use http discovery
[2023-08-21T12:33:43.011Z] Found firebase-functions binary at 'C:\Users\MYUSERNAME\documents\my-app\functions\node_modules.bin\firebase-functions'
Serving at port 8683shutdown 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"}}
Activity
james-dellow commentedon Aug 21, 2023
One other thing I noticed - the process is slow to start when it fails, but when it is successful, both the emulator and deploy start more quickly.
james-dellow commentedon Aug 26, 2023
While running the emulator today, I encountered the same error:
!! functions: Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification
I immediately re-ran the command and the functions emulator started correctly.
aalej commentedon Aug 29, 2023
Hi @james-dellow, taking a look into this, it looks like the cause is a network issue based of this log
checkFunctionsSDKVersion was unable to fetch information from NPM Error: spawnSync C:\Windows\system32\cmd.exe ETIMEDOUTfrom the debug.txt you provided. We will work on better surfacing this type of error to make it more visible.james-dellow commentedon Sep 3, 2023
Thanks @aalej - is there anything you can suggest that I can do in my environment to mitigate this?
ErlikC commentedon Oct 11, 2024
I wonder if this has anything to do with #5888.
I'm working with firebase-tools: 13.22.0
In my case I get
!! functions: Failed to start functions in C:\Users\MYUSERNAME\documents\my-app: FirebaseError: Failed to load function.There's an advice to set the environment variable FUNCTIONS_DISCOVERY_TIMEOUT=50, but it only worked for the
User code failed to load. Cannot determine backend specificationmessage.I found that modifying
firebase-tools\lib\emulator\functionsRuntimeWorker.jsin functionwaitForSocketReadyto something like this, stopped the message. I guess it's taking longer for the socket to be ready.Previously it had 30 secs.
It would be great if variable FUNCTIONS_DISCOVERY_TIMEOUT could be added to this spot (of course if that makes sense).