Home > Software design >  Node 16 unsupported for Google Cloud Functions
Node 16 unsupported for Google Cloud Functions

Time:11-04

I am a bit lost, I keep getting the following error when I try to deploy my Cloud Functions:

Error: package.json in functions directory has an engines field which is unsupported. Valid choices are: {"node": "8"}, {"node": "10"}, and {"node":"12"}.

My current node version in use is 16.15.0.

Here is the package.json :

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "engines": {
    "node": "16"
  },
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "@google-cloud/storage": "^6.6.0",
    "cors": "^2.8.5",
    "crypto-js": "^4.1.1",
    "firebase": "^9.13.0",
    "firebase-admin": "^11.2.0",
    "firebase-functions": "^4.0.2",
    "fs": "0.0.1-security",
    "html-pdf": "^3.0.1",
    "lodash": "^4.17.21",
    "moment-timezone": "^0.5.38",
    "os": "^0.1.2",
    "path": "^0.12.7",
    "raw-body": "^2.5.1"
  },
  "devDependencies": {
    "eslint": "^8.26.0",
    "eslint-plugin-promise": "^6.1.1"
  },
  "private": true,
  "type": "module"
}

I don't understand why I cannot deploy with node 16, since it is the recommended version: The Node.js Runtime

CodePudding user response:

Firebase cloud functions do support Node.js 16, so try to update all of your dependencies and check again if the error persists.

References:

CodePudding user response:

Today I restarted my mac, and the node version was back to 13 (13 was I think the default value).

The only thing I did before trying again was this command to set the node version to the latest once and for all:

nvm alias default node

Then I executed the firebase deploy command again and this time it worked...

FYI I am 100% sure yesterday I was set on node 16 (I used the command nvm use 16), that's why I have no idea what happened here, but now it seems to be fixed.

  • Related