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 - functions emulator fails to start or deploy fails #6285

Closed
james-dellow opened this issue Aug 21, 2023 · 5 comments · Fixed by #7838

Comments

@james-dellow
Copy link

james-dellow commented Aug 21, 2023

[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 8683

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

debug.txt

@james-dellow
Copy link
Author

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
Copy link
Author

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
Copy link
Contributor

aalej commented 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 ETIMEDOUT from the debug.txt you provided. We will work on better surfacing this type of error to make it more visible.

@james-dellow
Copy link
Author

Thanks @aalej - is there anything you can suggest that I can do in my environment to mitigate this?

@taeold taeold assigned taeold and unassigned blidd-google Sep 13, 2023
@ErlikC
Copy link

ErlikC commented 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 specification message.

I found that modifying firebase-tools\lib\emulator\functionsRuntimeWorker.js in function waitForSocketReady to something like this, stopped the message. I guess it's taking longer for the socket to be ready.

const timeout = new Promise((resolve, reject) => {
            setTimeout(() => {
                reject(new error_1.FirebaseError("Failed to load function."));
            }, 60000);

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).

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

Successfully merging a pull request may close this issue.

6 participants