node.jsfirebasegoogle-cloud-functionsfirebase-tools

Firebase deploy - 'runtime' field not found in firebase.json or package.json


I'm trying to deploy my firebase functions from multiple different folders using firebase deploy. During deployment I get this error:

Error: runtime field is required but was not found in firebase.json or package.json. To fix this, add the following lines to the functions section of your firebase.json: "runtime": "nodejs20" or set the "engine" field in package.json

I have set "engines" in package.json according to the documentation. Here is my package.json:

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "build:watch": "tsc --watch",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "20"
  },
  "main": "lib/src/index.js",
  "dependencies": {
    "firebase-admin": "^11.8.0",
    "firebase-functions": "^4.3.1"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.12.0",
    "@typescript-eslint/parser": "^5.12.0",
    "eslint": "^8.9.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.25.4",
    "firebase-functions-test": "^3.1.0",
    "typescript": "^4.9.0"
  },
  "private": true
}

My node, npm & firebase versions:

node -v
v20.9.0
npm -v
10.1.0
firebase --version
13.8.0

In the documentation i found that

The CLI uses the value set in firebase.json in preference to any value or range that you set separately in package.json.

So, here is my firebase.json:

{
  "functions": [
    {
      "source": "restapi",
      "codebase": "restapi",
      "ignore": [
        "venv",
        "virtualenv",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    },
    {
      "source": "functionsv2",
      "codebase": "py",
      "ignore": [
        "venv",
        "virtualenv",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    },
    {
      "source": "functionsv1",
      "runtime": "nodejs20",
      "codebase": "ts",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ]
}

Yet, I still encounter the same error. Moreover, when i try to set runtimes for the python functions like this:

{
      "source": "restapi",
      "runtime": "python310",
      "codebase": "restapi",
      "ignore": [
        "venv",
        "virtualenv",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    },

i get: Error: Unexpected runtime python310, even though after putting in a value such like python39 CLI says that:

Valid values are: - nodejs6 nodejs8 nodejs10 nodejs12 nodejs14 nodejs16 nodejs18 nodejs20 python310 python311 python312

so, python310 is clearly there.

I have read similar questions and still can't understand if i put the "runtime" field in the correct place, if I input a correct value, or if the issue lays within the firebase CLI configuration itself.


Solution

  • I had a similar problem with 'runtime' field missing on firebase deploy with Python cloud functions.

    Posted the issue on firebase tool's github and the workaround proposed was to delete the package.json file. The explanation is that package.json is only needed by firebase to determine the Node.js runtime version and with Python we don't need Node.js.

    Then make sure to add on firebase.json the "runtime" key with the required python version as value, e.g. "python311".

    This worked for me.