I'm trying to set up firebase in in my node.js server. In deploy.js I am setting up up like this:
const admin = require('firebase-admin/app');
const serviceAccount = require('../serviceAccountKey.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://projectName.firebaseio.com"
});
...
I am getting the error:
credential: admin.credential.cert(serviceAccount),
^
TypeError: Cannot read property 'cert' of undefined
at Object.<anonymous> (C:\Users\Uporabnik\hello-world\scripts\deploy.js:9:32)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
My package.json:
{
"name": "hardhat-project",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.6",
"ethers": "^5.6.9",
"hardhat": "^2.9.9"
},
"version": "1.0.0",
"description": "hello world smart contract",
"main": "hardhat.config.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.1",
"firebase-admin": "^11.0.0"
},
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC"
}
What could be causing it?
This is the solution:
Replace
const admin = require('firebase-admin/app');
with
const admin = require('firebase-admin');
You would use /app if you’re going to use modular approach