Local debug
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!
Hi bluelightning2k -- try the following:
- install the module (
npm install @google-cloud/functions-framework) tonode_modules - 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/
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.
Closing this. Please re-open if this doesn't work. I'd also love to get confirmation that this works for your purposes.
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!
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.
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
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.
Would be nice to have a doc for webstorm setup for local debugging.
Its ok, I managed to get it to work
I'll make a youtube video
@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
We already have more channels than I can manage well. For chat, we use the Google Cloud community on Slack.
ah didnt know there was one, cool
Added instructions: https://github.com/GoogleCloudPlatform/functions-framework-nodejs/tree/master/docs
@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.
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:
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 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!
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
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 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