Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 855
BATMAN_2008 Avatar asked Sep 24 '20 06:09

BATMAN_2008


2 Answers

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"}
  }
}
like image 146
Doug Stevenson Avatar answered Oct 16 '22 18:10

Doug Stevenson


To set the runtime ,set the version in the engines field in the package.json file that was created in your functions/ directory during initialization. For example, to use only version 10, edit this line in package.json:

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

The engines field is required; it must specify one of the supported Node.js versions in order for you to deploy and run functions. Currently, firebase init functions sets this field to node 10

like image 26
Vipul Patil Avatar answered Oct 16 '22 18:10

Vipul Patil