Skip to content

Function deployment fails with npm workspaces/nx - Error: spawn ./node_modules/.bin/firebase-functions ENOENT #4952

Closed

Description

@rahuld600

[REQUIRED] Environment info

firebase-tools: 11.8.0 (latest release)

Platform: : macOS

[REQUIRED] Test case

If I make a function on the index.js file, and then I try to deploy using:
firebase deploy --only functions:nameOfYourFunction
I get an Unexpected Error at the end.

[REQUIRED] Steps to reproduce

Using npm or whatever package manager you prefer, run these on your terminal,

npm install -g firebase-tools
firebase login
firebase init functions

Now under the functions folder, make sure you have installed node modules using npm install,
and finally you create a basic function you like on index.js after you are done importing stuffs, for example:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.yourFunctionName = functions.https.onRequest(async(req,res)=>{
functions.logger.log(res.body); //just for an example.
})

Now when you try to do:

firebase deploy --only functions:yourFunctionName

You'll see this error message in the end:

[debug] [2022-09-05T11:21:08.962Z] Building nodejs source
[debug] [2022-09-05T11:21:08.963Z] Could not find functions.yaml. Must use http discovery
[debug] [2022-09-05T11:21:08.972Z] Error: spawn ./node_modules/.bin/firebase-functions ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
[error]
[error] Error: An unexpected error has occurred.
[debug] [2022-09-05T11:21:09.063Z] Serving at port 9005

[REQUIRED] Expected behavior

Expected behaviour is that the function gets deployed successfully without any error.

[REQUIRED] Actual behavior

Actual behaviour is that function normally get's deployed successfully and just after this update, this issue came into play.

Activity

  1. rahuld600 commented on Sep 5, 2022

    @rahuld600
    Author

    I could fix this issue just by downgrading the version of firebase tools to v10.0.0 using:
    npm install -g [email protected]

  2. rahuld600 commented on Sep 5, 2022

    @rahuld600
    Author

    Since there might be something wrong with the new v11.8.0, so It would be really awesome if the engineers took a look at what's up with the latest release...so I am keeping this issue open.

  3. changed the title [-]Unexpected Error while deploying using "firebase deploy --only functions" in [email protected] (latest version).[/-] [+]Unexpected Error while deploying using "firebase deploy --only functions" in [email protected] (latest version) (Could not find functions.yaml. Must use http discovery).[/+] on Sep 5, 2022
  4. taeold commented on Sep 6, 2022

    @taeold
    Contributor

    Thanks for filing the issue @rahuld600!

    QQ1 - what tooling are you using for package management (yarn? npm)? Are you usign yarn/npm workspaces?
    QQ2 - have you run npm i before deploying your function?

  5. added
    Needs: Author Feedback
    on Sep 6, 2022
  6. rahuld600 commented on Sep 7, 2022

    @rahuld600
    Author

    @taeold Hello sir,
    First of all, thank you for checking out!
    QQ1 - I am using npm for package management.
    QQ2 - Yes sir! I ran npm install before deploying.

  7. added and removed
    Needs: Author Feedback
    on Sep 7, 2022
  8. vevepeter commented on Oct 25, 2022

    @vevepeter

    Thanks for filing the issue @[removed to avoid tagging]!

    QQ1 - what tooling are you using for package management (yarn? npm)? Are you usign yarn/npm workspaces? QQ2 - have you run npm i before deploying your function?

    Hey. If I may, what if they weren't using npm but yarn and yarn workspaces? We seem to be having the same issue, only with yarn workspaces and for firebase-tools v11.15.0.

    Would it be better if I created a new issue for this for full details, or is this fine? Here are some of the other relevant(?) packages and versions:
    "firebase": "9.12.1"
    "firebase-admin": "^11.2.0"
    "firebase-functions": "4.0.1"

  9. joonne commented on Oct 29, 2022

    @joonne

    Hey 👋

    I'm seeing a similarish issue with firebase-tools v11.15.0 when running firebase deploy --only functions --debug

    debug output:

    [2022-10-29T06:03:49.031Z] Building nodejs source
    [2022-10-29T06:03:49.032Z] Could not find functions.yaml. Must use http discovery
    [2022-10-29T06:03:49.195Z] Serving at port 9005
    
    [2022-10-29T06:03:49.372Z] Got response from /__/functions.yaml Failed to generate manifest from function source: Error
    [2022-10-29T06:03:49.381Z] shutdown requested via /__/quitquitquit
    
    Error: Failed to parse build specification:
    - FirebaseError Expect manifest yaml to specify a version number
    

    I deleted the existing functions as I thought it would have something do with the versioning but no dice.

    package.json contents:

    {
      "name": "functions",
      "scripts": {},
      "engines": {
        "node": "16"
      },
      "main": "lib/index.js",
      "dependencies": {
        "@google-cloud/firestore": "6.4.1",
        "axios": "1.1.3",
        "firebase-admin": "11.2.0",
        "firebase-functions": "4.0.1",
        "ksuid": "3.0.0",
        "purify-ts": "1.3.0",
        "stripe": "10.15.0",
        "uuid": "9.0.0"
      },
      "devDependencies": {
        "firebase-functions-test": "3.0.0",
        "typescript": "4.8.4"
      },
      "private": true
    }
    
  10. 48 remaining items

  11. Jimgitsit commented on Jan 23, 2023

    @Jimgitsit

    After upgrading to 11.21.0, I see this error when starting the functions emulator:
    Error: spawn /Users/.../functions/node_modules/.pnpm/[email protected][email protected]/node_modules/.bin/firebase-functions ENOENT
    Downgraded to 11.20.0 and error went away.

  12. edenhermelin commented on Jan 25, 2023

    @edenhermelin

    Could not find functions.yaml. Must use http discovery

    same here, the error appeared after upgrading from v11.19.0 to v11.21.0
    using pnpm

    is there another way to fix it beside downgrading?

  13. ChromeQ commented on Feb 1, 2023

    @ChromeQ

    I can confirm that v11.22.0 fixes this issue as described in #5448

  14. desk-pro commented on Feb 13, 2023

    @desk-pro

    As mentionned in #5482, I get following error when using v11.22.0 :

    Error: Failed to find location of Firebase Functions SDK. Please file a bug on Github (https://github.com/firebase/firebase-tools/).

  15. TacB0sS commented on Mar 13, 2023

    @TacB0sS

    @taeold

    We have encountered this issue where randomly we are able to deploy our gen v2 function and randomly fail with User code failed to load. Cannot determine backend specification error message.

    Deeper investigation shows the issue is not having the .yaml file which in turn resulted in an http call which I assumes generates that yaml file.

    that http call has a timeout of 30 sec, if the yaml generation was completed under 30 sec our function would deploy otherwise fail..

    attaching code snippet from the [email protected] sdk

    async function detectFromPort(port, project, runtime, timeout = 30000) {
        let res;
        const timedOut = new Promise((resolve, reject) => {
            setTimeout(() => {
                reject(new error_1.FirebaseError("User code failed to load. Cannot determine backend specification"));
            }, timeout);
        });
        while (true) {
            try {
                res = await Promise.race([(0, node_fetch_1.default)(`http://127.0.0.1:${port}/__/functions.yaml`), timedOut]);
                break;
            }
            catch (err) {
                if ((err === null || err === void 0 ? void 0 : err.code) === "ECONNREFUSED") {
                    continue;
                }
                throw err;
            }
        }
        const text = await res.text();
        logger_1.logger.debug("Got response from /__/functions.yaml", text);
        let parsed;
        try {
            parsed = yaml.load(text);
        }
        catch (err) {
            logger_1.logger.debug("Failed to parse functions.yaml", err);
            throw new error_1.FirebaseError(`Failed to load function definition from source: ${text}`);
        }
        return yamlToBuild(parsed, project, api.functionsDefaultRegion, runtime);
    }
    

    Would appreciate a quick fix for this issue.
    Adam.

  16. Fleker commented on Apr 5, 2023

    @Fleker

    I started encountering this in a project tonight, even after downgrading to v11.19. I can get it to succeed by commenting out a ton of my code but it consistently hits the error with my full code.

  17. ibnzahoor98 commented on Apr 7, 2023

    @ibnzahoor98

    I faced this issue

    [debug] [2023-04-07T12:56:12.957Z] Building nodejs source
    [debug] [2023-04-07T12:56:12.960Z] Could not find functions.yaml. Must use http discovery
    [debug] [2023-04-07T12:56:12.975Z] Found firebase-functions binary at 'G:\Github Projects\health-2077\health-2077\dist\functions\node_modules\.bin\firebase-functions'
    [debug] [2023-04-07T12:56:14.744Z] Error: spawn UNKNOWN
    

    on firebase tools version 11.25.3. After downgrading to 10.8.0 I was able to deploy my application to firebase hosting.

    Thank you @JoeEarly @binodnepali for point out what worked for you.

  18. ChromeQ commented on Apr 7, 2023

    @ChromeQ

    @ibnzahoor98 downgrading to such an older version is not really a long term fix imo. Plus this issue has been fixed in v11.22.0 as I outlined above.

    I'd recommend going back to this version to determine if this issue is the same cause or is a regression since then.
    I've kept up with the latest version and this error has not resurfaced so you may be experiencing a different problem with the same error message. And also try to delete node modules folder completely and even the package-lock or yarn-lock file too, and ensure the node version is modern.

    I can confirm that v11.22.0 fixes this issue as described in #5448

  19. ibnzahoor98 commented on Apr 7, 2023

    @ibnzahoor98

    @ibnzahoor98 downgrading to such an older version is not really a long term fix imo. Plus this issue has been fixed in v11.22.0 as I outlined above.

    I'd recommend going back to this version to determine if this issue is the same cause or is a regression since then. I've kept up with the latest version and this error has not resurfaced so you may be experiencing a different problem with the same error message. And also try to delete node modules folder completely and even the package-lock or yarn-lock file too, and ensure the node version is modern.

    I can confirm that v11.22.0 fixes this issue as described in #5448

    Thank you for pointing out. I will move to 11.22.0

  20. Fleker commented on Apr 14, 2023

    @Fleker

    I have just updated to 11.27.0 and am still seeing this error.

  21. desk-pro commented on Apr 20, 2023

    @desk-pro

    @Fleker Same for me

  22. Padreco-lbr commented on May 3, 2023

    @Padreco-lbr

    This problem is still happening, downgrading to versions 11.17.0 or 11.22.0 or latest is currently not working for us, can someone please check this? Its a development blocker since deployment is impossible AND emulators won't start.

  23. servefast-cto commented on Sep 25, 2024

    @servefast-cto

    Happening for me when updated to 12.5.0 worked for 12.1.0

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

Metadata

Metadata

Assignees

Labels

Needs: Author Feedbackapi: functionstype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions