Currently, I am engaged in a project which involves using Express in Firebase functions to execute server-side rendering pages with the help of Handlebars. Everything is running smoothly, but the problem arises when I incorporate the Firestore admin SDK and encounter the following error:
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
The code snippet causing this issue can be found in my functions/index.js file
const functions = require('firebase-functions');
const express = require('express')
const engines = require('consolidate')
const cookieParser = require('cookie-parser')
const serviceAccount = require('./lendme360-firebase-adminsdk-easkh-d9130c0494.json');
var admin = require('firebase-admin')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
})
const stripe = require('stripe')('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
const db = admin.firestore()
const app = express()
app.engine('hbs', engines.handlebars)
app.set('views', './views')
app.use(cookieParser())
app.set('view engine', 'hbs')
...
...
...
...
...
exports.app = functions.https.onRequest(app)
The functionality seems to be working fine overall. However, the error occurs specifically when attempting to use const db = admin.firestore(). I have also experimented with emulators for both functions and firestore without resolution.
I would greatly appreciate any assistance in identifying where I may be going wrong here.
Thank you in advance.