Vitaly Menchikovsky
Vitaly Menchikovsky

Reputation: 8934

Unable to debug firebase functions

I am trying to debug my js code the runs on firebase functions. My steps were: install from functions

npm install --save @google-cloud/debug-agent

added index.js:

require('@google/cloud-debug').start();

when I tryed to run

firebase deploy --only functions

got an error :

Error: Error parsing triggers: Cannot find module '@google/cloud-debu
g'

Try running "npm install" in your functions directory before deployin

Upvotes: 0

Views: 1948

Answers (2)

jimmont
jimmont

Reputation: 2543

try: ndb firebase serve

debugger breakpoints are hit with stack traces visible, note it's a little slow so give the debugger time to instrument the child processes

Additionally I was able to debug cloud functions in isolation using (caps for removed values):

GCLOUD_PROJECT=THE-FIREBASE-PROJECT node --inspect-brk /path/to/functions-framework --target FUNCTION-NAME --port=5000

where functions-framework simply expands to the full path for the installed functions-framework (global in my case) and the working directory contains the target index.js for functions.

Alternately when or where the FIREBASE_CONFIG is needed try this format adjusted to fit: FIREBASE_CONFIG="{\"databaseURL\":\"https://YOUR-FIREBASE-PROJECT.firebaseio.com\",\"storageBucket\":\"YOUR-FIREBASE-PROJECT.appspot.com\",\"projectId\":\"YOUR-FIREBASE-PROJECT\"}

Upvotes: 0

Ali Ijaz Sheikh
Ali Ijaz Sheikh

Reputation: 89

The addition to index.js should be:

require('@google-cloud/debug-agent').start();

or better:

require('@google-cloud/debug-agent').start({ allowExpressions: true });

We recently renamed the module, and it is possible that the instructions you are following are partially out of date. Can you point us to the instructions you have been following?

Also note that support for debugging cloud functions is experimental at this point. There are certain cases (dependent on the traffic to the function) where you function may finish before the debug-agent has a chance to initialize/register. We're currently looking into how to address this.

Upvotes: -1

Related Questions