Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Functions Deploy Error- SyntaxError: Unexpected token '?'

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
}
like image 409
Lance Samaria Avatar asked Feb 03 '26 00:02

Lance Samaria


2 Answers

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

like image 163
Lance Samaria Avatar answered Feb 04 '26 13:02

Lance Samaria


For users in node 12.x version:

npm install --save [email protected] 
like image 28
nvvetal Avatar answered Feb 04 '26 14:02

nvvetal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!