В основном я пытаюсь, чтобы функция firebase просто выводила значения в документе, я добилась этого только локально ... но функция не будет развернута в облаке. Ниже приведена функция
const functions = require('firebase-functions');
const firebase = require('firebase/app');
require('firebase/firestore');
const firebaseConfig = {
projectId: "covid-info-bw"
};
const db = firebase
.initializeApp(firebaseConfig)
.firestore()
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase! Dawg I am beast");
});
exports.getData = functions.https.onRequest((req, res) => {
const docRef = db.collection('FunctionTest').doc('Cm38kBYShNnyuLVpizcy');
const getDoc = docRef.get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
return res.send('Not Found')
}
console.log(doc.data());
return res.send(doc.data());
})
.catch(err => {
console.log('Error getting document', err);
});
Это фрагмент из пакета. json
"dependencies": {
"@firebase/app": "^0.6.1",
"@firebase/firestore": "^1.14.0",
"@google-cloud/firestore": "^3.7.4",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.0"
},
Это ошибка, которую я получаю от запуска "firebase deploy --only functions: getData, функции: helloWorld "
λ firebase deploy --only functions:getData,functions:helloWorld
=== Deploying to 'covid-info-bw'...
i deploying functions
Running command: npm --prefix "%RESOURCE_DIR%" run lint
> functions@ lint M:\VueAdventures\covid-info-bw\functions
> eslint .
+ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (41.45 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: current functions in project: getData(us-central1), helloWorld(us-central1)
i functions: uploading functions in project: helloWorld(us-central1), getData(us-central1)
i functions: updating Node.js 8 function helloWorld(us-central1)...
i functions: updating Node.js 8 function getData(us-central1)...
! functions[getData(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase/app'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/index.js:2:18)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
! functions[helloWorld(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase/app'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/index.js:2:18)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Functions deploy had errors with the following functions:
getData
helloWorld
To try redeploying those functions, run:
firebase deploy --only functions:getData,functions:helloWorld
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.