I've created a function and it works to deploy it when it is in index.js but I've gone quite a few functions and the file kinda gets bigger. I've tried to move a function in a different file (e.g. get_data.js) but when I try to deploy the function I get the following error
The following functions are found in your project but do not exist in your local source code:
getData(us-central1)
My project structure looks like this now:
node_modules/
index.js
get_data.js //this is where I've moved the function
...
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": "16"
},
"main": "index.js",
"dependencies": {
"dateformat": "^4.6.3",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0",
"node_extra_ca_certs_mozilla_bundle": "^1.0.5",
"nodemailer": "^6.7.7",
"queryselector": "^0.1.0",
"queryselectorall": "^0.1.0",
"ssl-root-cas": "^1.3.1"
},
"devDependencies": {
"@babel/eslint-parser": "^7.18.9",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
and
get_data.js
exports.getAirQualityData = functions.pubsub.schedule("every 5 minutes").onRun(async (context) => { };
Any help in fixing this?
CodePudding user response:
All Cloud Functions must be exported from index.js
. Try adding this in index.js
:
/* Initialize Admin SDK */
export { getAirQualityData } from "./get_data.js"
This is also explained in the documentation.