firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Function emulator unable to recognize multiple "codebase" entries

Open subimage opened this issue 2 years ago • 2 comments

[REQUIRED] Environment info

firebase-tools: 11.7.0

Platform: macOS

[REQUIRED] Test case

project structure

/
  firebase.json
  /packages
    /web (next.js project)
    /functions (regular firebase functions)

firebase.json file

{
  "functions": [
    {
      "source": "./packages/web",
      "codebase": "nextJs",
      "predeploy": [
        "yarn --cwd \"$RESOURCE_DIR\" run lint",
        "yarn --cwd \"$RESOURCE_DIR\" run build"
      ],
      "runtime": "nodejs16"
    },
    {
      "source": "./packages/functions",
      "codebase": "functions",
      "predeploy": [
        "yarn --cwd \"$RESOURCE_DIR\" run lint",
        "yarn --cwd \"$RESOURCE_DIR\" run build"
      ],
      "runtime": "nodejs16"
    }
  ],
  "emulators": {
    "functions": {
      "port": 5001
    }
  }
}

[REQUIRED] Steps to reproduce

  • Create project structure as above
  • Use the firebase.json file above
  • Start firebase hosting emulator using firebase emulators:start

[REQUIRED] Expected behavior

In the latest documentation about organizing functions in a monorepo it appears that we should be able to use multiple function directories from the same project. I'd expect that the hosting emulator would understand the array directive under the functions key, but it does it.

[REQUIRED] Actual behavior

The firestore emulator complains that ⚠ functions: The functions emulator is configured but there is no functions source directory. Have you run firebase init functions?

Screen Shot 2022-08-19 at 6 44 12 AM

subimage avatar Aug 19 '22 15:08 subimage

I've also encountered this issue, going down the rabbit hole the errors is here, the getFunctionsSDKVersion function runs the command:

npm list firebase-functions --json=true

In a non-monorepo setup that will yield:

{
  "name": "functions",
  "dependencies": {
    "firebase-functions": {
      "version": "3.23.0",
      "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-3.23.0.tgz"
    }
  }
}

Whereas in a monorepo results in:

{
  "version": "1.0.4",
  "name": "monorepo",
  "dependencies": {
    "@backend": {
      "version": "1.0.0",
      "resolved": "file:../../packages/backend",
      "dependencies": {
        "firebase-functions": {
          "version": "3.21.2",
          "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-3.21.2.tgz"
        }
      }
    }
  }
}

Finally, when reading the version, this code gets executed:

_.get(output, ["dependencies", "firebase-functions", "version"]);

That will work on the first payload but fail for the second one.

ElianCordoba avatar Sep 06 '22 18:09 ElianCordoba

I have the same issue

diegofhe avatar Oct 07 '22 22:10 diegofhe

Hi everyone, you all noticed an area of improvement in the functions emulator! We currently have a feature request bug for adding codebase support - #4878

I'm going to close this so we don't have duplicate issues open. Thanks

colerogers avatar Dec 14 '22 16:12 colerogers