functions-framework-nodejs icon indicating copy to clipboard operation
functions-framework-nodejs copied to clipboard

Local debug

Open bluelightning2k opened this issue 7 years ago • 31 comments

Hi, the readme doesn't mention anything about local debugging.

Is breakpoint debugging supported?

This would be a necessary feature for us to begin using Functions Framework. Is this supported, and can you consider updating the readme to address offline debugging (even if it's just to state that it's not supported, or to suggest a workaround).

Thanks!

bluelightning2k avatar Apr 10 '19 10:04 bluelightning2k

Hi bluelightning2k -- try the following:

  1. install the module (npm install @google-cloud/functions-framework) to node_modules
  2. run your function using node --inspect, e.g., node --inspect node_modules/@google-cloud/functions-framework <FLAGS>

Where <FLAGS> correspond to Functions Framework flags (e.g., target) as documented on the README.

That should produce something like:

node --inspect node_modules/@google-cloud/functions-framework --target helloWorld
Debugger listening on ws://127.0.0.1:9229/c3574d99-20f7-42e8-b34c-dd9ca27f4876
For help see https://nodejs.org/en/docs/inspector
Serving function...
Function: helloWorld
URL: http://localhost:8080/

stew-r avatar Apr 10 '19 18:04 stew-r

I also tried this out using npx: npx --node-arg=--inspect @google-cloud/functions-framework --target=helloWorld

As a non-Node.js developer, the npx tooling is pretty slick. You should also be able to pass arguments to Node using NODE_OPTIONS.

stew-r avatar Apr 10 '19 20:04 stew-r

Closing this. Please re-open if this doesn't work. I'd also love to get confirmation that this works for your purposes.

stew-r avatar Apr 11 '19 17:04 stew-r

Hi @stew-r , This worked perfectly!

Specifically: your first method worked perfectly, even in a complex setup. We are using WebPack to do a reasonably complicated build, and we setup VSCode to do the build, run/restart the function, and attach the debugger - all by pressing F5.

The NPX method didn't seem to support reloading in this configuration. So if you add one to the documentation (highly recommended) I'd choose the first method.

Thank you!

bluelightning2k avatar May 09 '19 13:05 bluelightning2k

Specifically: your first method worked perfectly, even in a complex setup. We are using WebPack to do a reasonably complicated build, and we setup VSCode to do the build, run/restart the function, and attach the debugger - all by pressing F5.

That's awesome! I'm glad you were able to make this work so seamlessly. Do you think there would be any value in maybe writing a small blog/Medium post about your setup? I'm sure other developers could benefit from your learnings.

stew-r avatar May 09 '19 17:05 stew-r

In the latest version of functions-framework (1.1.0) node --inspect node_modules/@google-cloud/functions-framework --function-target helloWorld this command does not work. Instead please use node --inspect node_modules/@google-cloud/functions-framework --target helloWorld

@stew-r Can you please write a blog post on how to make basic debug work because it is very hard to find documentation on functions-framework

darshan-willow avatar May 10 '19 08:05 darshan-willow

Good catch. I edited my comments to change function-target to target.

I probably won't have time to write a blog post about debugging. But I'll see if we can add something to the Functions Framework readme or directly on the Cloud Functions docs.

stew-r avatar May 10 '19 23:05 stew-r

Would be nice to have a doc for webstorm setup for local debugging.

quantuminformation avatar May 27 '19 07:05 quantuminformation

Its ok, I managed to get it to work

Screenshot 2019-05-27 at 09 57 06

I'll make a youtube video

quantuminformation avatar May 27 '19 07:05 quantuminformation

@stew-r I created a Discord server for GCP and have a channel for functions if you're interested. Good for stuff you don't want to add to the noise of github issues.

https://discord.gg/9yGuxRV

quantuminformation avatar May 27 '19 08:05 quantuminformation

We already have more channels than I can manage well. For chat, we use the Google Cloud community on Slack.

stew-r avatar May 28 '19 21:05 stew-r

ah didnt know there was one, cool

quantuminformation avatar May 28 '19 21:05 quantuminformation

Added instructions: https://github.com/GoogleCloudPlatform/functions-framework-nodejs/tree/master/docs

stew-r avatar Jul 19 '19 21:07 stew-r

@stew-r I think this issue should be re-opened. @google-cloud/functions-framework requires node to be ">=10.0.0" while Firebase Requires node v8, so we can't have both firebase and functions-framework installed at the same time.

I'm aware of the --ignore-engines, but still it's not a production-ready solution.

wujekbogdan avatar Aug 28 '19 13:08 wujekbogdan

I think Firebase has its own local emulation solution, no? You shouldn't need to use/rely on this as a Firebase customer.

stew-r avatar Aug 28 '19 16:08 stew-r

@stew-r:

You shouldn't need to use/rely on this as a Firebase customer.

you shouldn't but fact of the matter is that AFAIK the firebase CLI has no way for you to debug the functions..

regarding this or firebase's method (in case any exists) is there a way to automatically reload the code in case of changes?

Many TIA!

joantune avatar Jan 23 '20 14:01 joantune

@joantune If there's an issue with Firebase Functions or the firebase CLI, that should be reported upstream with https://github.com/firebase/firebase-tools.

If there's some other issue with this framework, please open a new issue and we'll look at it!

grant avatar Jan 23 '20 14:01 grant

Ok - managed to do something like that with Nodemon - and setting on PyCharm (or whichever debugger/IDE) the setting to reconnect automatically

RN I'm using something like:

FIREBASE_CONFIG="<escaped JSON of FIREBASE config>" GCLOUD_PROJECT="project id" ./node_modules/.bin/nodemon -e ts --exec "tsc && node --inspect node_modules/@google-cloud/functions-framework --target app "

it feels like it should be easier

joantune avatar Jan 23 '20 14:01 joantune

I was really struggling to start the debugger in VS Code on Windows, but this did the trick:

npx --node-options=--inspect @google-cloud/functions-framework --target=helloWorld

Unfortunately, the explanation here just spits some errors for me: https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/docs/debugging.md

Youlean avatar Feb 12 '22 00:02 Youlean

@Youlean Using npx is probably a better solution. What was the windows issue you were facing? Bad paths?

We can update the docs to use npx. https://github.com/GoogleCloudPlatform/functions-framework-nodejs/pull/429

grant avatar Feb 12 '22 00:02 grant