Error when starting firebase emulator with only funtions option - firebase

When trying to use the cloud functions emulator, I get a message stating:
function ignored because the firestore emulator does not exist or is not running
I have tried mentioned here: (Firestore/Firebase Emulator Not Running).
My functions/package.json looks like this:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.1.0"
},
"devDependencies": {
"eslint": "^5.12.0",
"eslint-plugin-promise": "^4.0.1",
"firebase-functions-test": "^0.1.6"
},
"private": true
}
Command I'm using to start the emulator:
firebase emulators:start --only functions
This is the output I'm getting:
i Starting emulators: ["functions"]
! Your requested "node" version "8" doesn't match your global version "10"
+ functions: Emulator started at http://localhost:5001
i functions: Watching "C:\Users\MyName\Documents\MyProject\functions" for Cloud Functions...
i functions[updateFunction]: function ignored because the firestore emulator does not exist or is not running.
+ All emulators started, it is now safe to connect.
I am doing a console.log in the function but I don't see it on the port (5001).
Any help would be appreciated.

If you want to trigger a Firestore function, you will need to make that change in the local Firestore emulator. Locally emulated functions don't respond to actual cloud-hosted databases. The emulation on all products must be local.

functions[updateFunction]: function ignored because the firestore emulator does not exist or is not running.
Maybe the 'updateFunction' is the handler function for watching a change of your firestore documents, isn't it?
So you might need to start firestore at the same time with functions.
Just execute without --only option with the firebase.json configurations
{
"hosting": {
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
},
"functions": {
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"hosting": {
"port": 5000
},
"ui": {
"enabled": true,
"host": "localhost",
"port": 4000
}
}
}
And if you want to connect your server-side functions with your IDE for debugging, you need '--inspect-functions' option, or you just have to check logs in the emulator log page "http://localhost:4000/logs"
firebase emulators:start --inspect-functions

Related

TypeError: Cannot read property 'SDK_VERSION' of undefined

I already have a firebase functions project setup in some folder in my computer but was trying to set it up somewhere else. When doing that, it happens to mess up something somewhere and i now get that error when deploying my functions using firebase deploy :
functions# build C:\Users\bertr\Documents\GitHub\GreenplayFirebaseFunctions\functions
> tsc
+ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
+ functions: required API cloudbuild.googleapis.com is enabled
+ functions: required API cloudfunctions.googleapis.com is enabled
Error: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'SDK_VERSION' of undefined
at registerDatabase (C:\Users\bertr\Documents\GitHub\GreenplayFirebaseFunctions\functions\node_modules\#firebase\database\dist\index.node.cjs.js:15610:28)
at Object.<anonymous> (C:\Users\bertr\Documents\GitHub\GreenplayFirebaseFunctions\functions\node_modules\#firebase\database\dist\index.node.cjs.js:15645:5)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at FirebaseNamespace.get (C:\Users\bertr\Documents\GitHub\GreenplayFirebaseFunctions\functions\node_modules\firebase-admin\lib\firebase-namespace.js:259:38)
at Object.<anonymous> (C:\Users\bertr\Documents\GitHub\GreenplayFirebaseFunctions\functions\lib\firebase\firebase.js:13:20)
Tried to upgrade firebase-tools, reinstalling firebase, setup account again but i still get that error. Maybe that has a link to firebase SDK V8 and 9 but i'm not sure... I did'nt change anything in my code.
here's my firebase.json file :
{
"functions": {
"predeploy": "npm --prefix \"$RESOURCE_DIR\" run build",
"source": "functions"
},
"emulators": {
"functions": {
"port": 8201
},
"firestore": {
"port": 9288
},
"database": {
"port": 6120
},
"ui": {
"enabled": true
}
}
}
and my package.json file :
{
"name": "functions",
"scripts": {
"build": "tsc",
"serve": "npm run build && firebase emulators:start --import ../../database",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "npm run build && firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha -r ts-node/register tests/**/*.test.ts"
},
"engines": {
"node": "10"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.4.2",
"firebase-functions": "^3.13.0",
"geofire-common": "^5.2.0",
"geolib": "^3.3.1",
"moment-timezone": "^0.5.32",
"tmp": "^0.2.1",
"xlsx": "^0.17.2"
},
"devDependencies": {
"#types/chai": "^4.2.18",
"#types/mocha": "^8.2.2",
"#types/tmp": "^0.2.1",
"chai": "^4.3.4",
"firebase-functions-test": "^0.2.0",
"mocha": "^9.0.0",
"ts-node": "^9.0.0",
"typescript": "^3.8.0"
},
"private": true
}
Thanks a lot guys!
Turns out i needed to update firebase-admin to latest version inside functions folder..
npm i firebase-admin
works for me!

Firebase Cloud Functions - Error parsing triggers: Cannot find module 'core-js/fn/reflect'

While trying to redeploy a function I now get this error message: Error parsing triggers: Cannot find module 'core-js / fn / reflect'.
Here's my 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": "14"
},
"main": "index.js",
"dependencies": {
"#google-cloud/logging": "^9.1.0",
"#woocommerce/woocommerce-rest-api": "^1.0.1",
"algoliasearch": "^4.8.5",
"cors": "^2.8.5",
"csvtojson": "^2.0.10",
"express": "^4.17.1",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.14.1",
"mkdirp": "^1.0.4",
"stripe": "^8.137.0"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
In index.js i use
const cors = require('cors')({origin: true});
....
exports.StripeEvents = functions.https.onRequest((req, res) => {
cors(req, res, () => {
//// some code that worked great
}
}
I do not use cors-js package at all...
Where does the problem comes from?
Thank you
depending the browser that you are using and the Javascript that you are using in some cases they do not support all the features required by Firebase so you need to at the Polyfills, in this documentation they show you the way to add the Polyfills to your app, the no recommended way to do it is with the core-js library, feel free to do it what you want.
I quick way to solve the error could be go to the directory where your functions live and execute:
solution install core-js#2.6.5

Firebase init "Node.js 8 has been deprecated." [duplicate]

This question already has an answer here:
Updating cloud function to suitable Node js version
(1 answer)
Closed 2 years ago.
When I run firebase init to start a new project the package.json file is created automatically (as below) when I go to the firebase dashboard it then throws this warning"
Starting NaN, NaN, we'll no longer support new deploys or updates of Node.js 8 functions.
Starting NaN, NaN, we'll no longer support executions of existing Node.js 8 functions.
how do you init and specify the version? Or what is the workaround?
{
"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": "8"
},
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"
},
"devDependencies": {
"eslint": "^5.12.0",
"eslint-plugin-promise": "^4.0.1",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
** moderator I did not come across similar questions because they way it was worded did not show up in google. This post per day traffic is evidence that it is helpful for the community**
You have to change your package.json
Where you have:
"engines": {
"node": "8"
}
change to:
"engines": {
"node": "10"
},
As stated by firebase documentation.

Debug firebase functions locally in VSCode with latest version of firebase and node v10 [duplicate]

This question already has answers here:
Functions debugging in VS Code
(6 answers)
Closed 2 years ago.
There seem to be many examples for #google-cloud/functions-emulator on the web but this has become deprecated now. I went through latest firebase docs Test functions interactively where we can test the functions locally using shell.
I tried debugging in VSCode but whenever I hit the debugger button, VSCode gives me this warning and then halt debugging immediately:
C:\Program Files\nodejs\node.exe --inspect-brk=46655 functions\lib\index.js
Debugger listening on ws://127.0.0.1:46655/c8545176-06c0-4b95-80ec-bcba4ca9d90e
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail
setup.js:53
I also initialized the admin object in ts/js code but debugger gave the same issue:
const admin = require("firebase-admin");
if (!admin.apps.length)
admin.initializeApp({
projectId: "...",
appId: "...",
databaseURL: "...",
storageBucket: "...",
apiKey: "...",
authDomain: "...",
messagingSenderId: "...",
measurementId: "..."
});
VSCode launch.json
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${file}",
"outFiles": ["${workspaceFolder}/**/*.js"]
}
]
firebase functions package.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^8.6.0",
"firebase-functions": "^3.3.0"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6",
"tslint": "^5.20.1",
"typescript": "^3.7.2"
},
"private": true
}
firebase.json:
{
"hosting": {
"public": "_site",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
},
"rewrites": [
{
"source": "/bigben",
"function": "bigben"
},
{
"source": "**",
"destination": "/index.html"
}
],
"cleanUrls": true
}
}
Platform: Windows 10
Node: v10
Project: Firebase web app with Typescript functions
firebase: 7.8.1.
I wonder if it's all possible to put breakpoints and run the debugger in VSCode for latest firebase functions.
It's not currently supported by the emulators in the Firebase CLI, but the feature is being worked on. You can read about it here:
https://github.com/firebase/firebase-tools/issues/1360

firebase functions:shell onWrite property undefined

I am trying to test my cloud functions locally. I am using the command firebase functions:shell which starts the emulator successfully. I have the following cloud function in my index.ts:
export const stripeCharge = functions.region('europe-west1').database
.ref('/payments/{userId}/{paymentId}')
.onWrite(async (change, context) => {
someCode;
});
I read that you should invoke an onWrite firestore function the following way (https://firebase.google.com/docs/functions/local-shell):
stripeCharge({before: "oldData", after: "newData"})
However, this results in the following error:
'Successfully invoked function.'
firebase > ! TypeError: Cannot read property 'eventType' of undefined
at cloudFunction (C:\Users\Jesper\intergun\functions\node_modules\firebase-functions\lib\cloud-functions.js:80:40)
at Run (C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:458:20)
at C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:442:19
at Generator.next (<anonymous>)
at C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)
at Run (C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:435:12)
at C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:457:15
at Generator.next (<anonymous>)
! Your function was killed because it raised an unhandled error.
The error happens in some other file and I'm not sure why. What am I missing?
Edit: My package.json:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"main": "lib/index.js",
"dependencies": {
"#google-cloud/storage": "^2.5.0",
"#types/fs-extra": "^7.0.0",
"firebase-admin": "^8.1.0",
"firebase-functions": "^3.0.1",
"fs-extra": "^8.0.1",
"mailgun-js": "^0.22.0",
"sharp": "^0.22.1",
"stripe": "^7.1.0"
},
"devDependencies": {
"#types/sharp": "^0.22.2",
"#types/stripe": "^6.30.0",
"firebase-functions-test": "^0.1.6",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"private": true
}
After replicating this I've found this thread it looks there is an open case for this issue.
The similar setup works fine for Firestore, but the issue seems to to be with the RTDB, I assume we have to wait until they solve it, sorry :(

Resources