Yesterday Night I deployed my functions and the deployment was successfull without any errors.
But when i tried to execute/call the function it throwed following error and logged in firebase console :
{ Error: Failed to import the Cloud Storage client library for Node.js. Make sure to install the "@google-cloud/storage" npm package. Original error: SyntaxError: Unexpected token {
at new FirebaseError (/srv/node_modules/firebase-admin/lib/utils/error.js:43:28)
at new Storage (/srv/node_modules/firebase-admin/lib/storage/storage.js:65:19)
at /srv/node_modules/firebase-admin/lib/firebase-app.js:255:20
at FirebaseApp.ensureService_ (/srv/node_modules/firebase-admin/lib/firebase-app.js:376:23)
at FirebaseApp.storage (/srv/node_modules/firebase-admin/lib/firebase-app.js:253:21)
at FirebaseNamespace.fn (/srv/node_modules/firebase-admin/lib/firebase-namespace.js:292:45)
at Object.exports.processCard (/srv/Files/process.js:157:24)
at Busboy.bus.on (/srv/index.js:44:13)
at emitNone (events.js:106:13)
at Busboy.emit (events.js:208:7)
errorInfo:
{ code: 'storage/missing-dependencies',
message: 'Failed to import the Cloud Storage client library for Node.js. Make sure to install the "@google-cloud/storage" npm package. Original error: SyntaxError: Unexpected token {' } }
after that i tried on more time ,to check if the error has gone, but then it throwed following:
Error: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
at FirebaseAppError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:43:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:89:28)
at new FirebaseAppError (/srv/node_modules/firebase-admin/lib/utils/error.js:124:28)
at FirebaseNamespaceInternals.initializeApp (/srv/node_modules/firebase-admin/lib/firebase-namespace.js:68:23)
at FirebaseNamespace.initializeApp (/srv/node_modules/firebase-admin/lib/firebase-namespace.js:423:30)
at Object.exports.processCard (/srv/Files/process.js:140:15)
at Busboy.bus.on (/srv/index.js:44:13)
at emitNone (events.js:106:13)
at Busboy.emit (events.js:208:7)
at Busboy.emit (/srv/node_modules/busboy/lib/main.js:37:33)
errorInfo:
{ code: 'app/duplicate-app',
message: 'The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.' },
codePrefix: 'app' }
I executed the function locally and everything was good function executed without any errors.
The weired part is that i never actully used google-storage library i use firebase-admin sdk to generate a signedURL and this is the function of generation of singedURL:
admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "urlToDatabase"
});
function getSignedUrl(file) {
console.time('URLGenerated ');
let options = { action: 'read', expires: Date.now() + 5 * 60 * 1000 }; // 5min Expiration Time
let bucketFileName = path.basename(file);
return bucket.upload(file, { destination: `public/${bucketFileName}`})
.then(() => {
return bucket.file(`public/${bucketFileName}`).getSignedUrl(options)
.then((urls) => {
fs.unlinkSync(file);
console.timeEnd('URLGenerated ');
return urls[0];
})
.catch((e) => {
console.log('Link Generation Error' + e);
});
}).catch((e) => console.log(e));
}
In the second error it says that i've initialized admin twice but i don't think i've done that. I double checked evything and also tried emulator as i mentioned before.
and this is package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"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": "8"
},
"main": "index.js",
"dependencies": {
"@google-cloud/storage": "^5.3.0",
"busboy": "^0.3.1",
"docx": "^5.3.0",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0",
"gs4fb": "^1.1.0"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
It is 20 Hours now and my function is down. The functions is heart of my website.
Where is the problem ?
I've updated to latest version of firebase-admin, firebase-functions library and firebaseCLI not because i needed just because it was warning me everytime.
Latest version of firebase-Admin was causing the error. Rolled back to 8.13 and everything was on track.
Seriously Never Update to latest if NOT REQUIRED.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With