Search code examples
node.jsfirebasegoogle-cloud-functionsfirebase-hostingfirebase-cli

firebase deploy command for Node.js application results in Error: `runtime` field is required but was not found in firebase.json


I am trying to deploy my Node.js application in firebase but when I run the command it results in the error Error: runtime field is required but was not found in firebase.json.

enter image description here

I tried running the command firebase serve --only functions,hosting and everything works fine locally so I would like to deploy and provide the link to my colleagues for the user testing but I am unable to do it using the firebase deploy command.

I tried adding the command to my firebase.json file but still no luck. Here is my original firebase.json file:

{
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ]
  }
}

After getting the error I changed to this:

{
  "hosting": {
    "public": "public",
    "runtime": "nodejs10",
    "rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ]
  }
}

Still getting the error, I am bit confused where exactly I need to add the command "runtime": "nodejs10",. I tried looking but could not find any relevant article on the similar issue, can anyone please help me.


Solution

  • The error message says to add it to the "functions" section. You're adding it to the "hosting" section, which won't work. The runtime choice is made for Cloud Functions, not Firebase Hosting. They are different products with different configuration.

    The message is also not entirely accurate about what to add.

    Add the runtime to the functions section as discussed in the documentation:

    {
      "functions": {
        "engines": {"node": "10"}
      }
    }