14

I just updated to:

npm: 8.11.0
node: v16.15.1

New Edit:

I just updated again sudo n latest:

npm: 8.12.1
node: v18.4.0

I'm trying to deploy a new cloud function firebase deploy --only functions:deleteUser but I keep getting a cli error:

Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause

When I look at the log:

deleteUser

Detailed stack trace: /workspace/node_modules/firebase-admin/lib/app/firebase-namespace.js:84

this.INTERNAL = new FirebaseNamespaceInternals(appStore ?? new lifecycle_1.AppStore());

Provided module can't be loaded. 

Is there a syntax error in your code?

SyntaxError: Unexpected token '?'

at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/workspace/node_modules/firebase-admin/lib/default-namespace.js:19:30)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

Could not load the function, shutting down.

Index.js:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.deleteUser = functions.https.onCall((data, context) => {

    const userID = data.userID;

    admin.auth().deleteUser(userID)
    .then(() => {
        console.log('Successfully deleted userID: ', userID);
        return true // without this Return I get a different error: Each then() should return a value or throw  promise/always-return
    })
    .catch((error) => {
        console.log('Error deleting user: ', error);
    });
});

New Edit Again

Package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "12"
  },
  "main": "index.js",
  "dependencies": {
    "@google-cloud/logging": "^8.1.1",
    "firebase-admin": "^11.0.0",
    "firebase-functions": "^3.11.0",
    "save": "^2.4.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}
3
  • 2
    Could you check what's version of Node runtime specified in your functions package.json file, like described here?
    – raina77ow
    Commented Jun 20, 2022 at 23:41
  • it says: "engines": { "node": "12" }. I'm going to add the entire package.json to the question Commented Jun 20, 2022 at 23:43
  • 1
    @raina77ow thanks for the tip. I only had to change it to "16" and now it deploys fine. Commented Jun 21, 2022 at 0:00

4 Answers 4

26

Thanks to the tip by @raina77ow in the comments. I had to go inside my package.json file and simply change the node version from 12 to 16

old:

"engines": {
    "node": "12" // causes error
  }

new:

"engines": {
    "node": "16" // error is now gone
  }

Update: I posted this a while back, Firebase is now on "node": "20" look here

2
  • In my case I was deploying with serverless, so I also needed to update the runtime in the serverless.yml config file to nodejs16.x
    – justin
    Commented Jul 21, 2022 at 19:19
  • 100! All the links that gcloud cli gave in the terminal were unhelpful at best. They pointed me to check logging to try to figure out what was wrong with my code - turns out, nothing. It was actually that Cloud Functions doesn't support the Node version that was originally used in the config when the project was created.
    – wildcat12
    Commented Jan 18, 2023 at 21:03
8

For users in node 12.x version:

npm install --save [email protected] 
1
  • 1
    This worked for me with docker ubuntu image Commented Apr 17, 2023 at 0:12
1

The suggested solutions didn't work for me because I already use node version 16. What worked for me was replacing the firebase toolset with the latest version. I was surprised but it cleared the error. You can do that using the following command:

sudo npm install -g firebase-tools@latest --force

Now be aware that --force shouldn't be used unless you want to really replace the existing toolset (In general some should be careful with that command). Sudo was necessary in my case to execute the command with elevated rights. After that firebase deployment should work.

0

Upgrade the Node version from package.json as well as the runtime from firebase.json

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.