I've started a firebase cloud functions project and want to know how i can get the debugging within the WebStorm IDE running?
I've read that i can archive my goal using @google-cloud/functions-emulator. Therefore I installed it and followed this documentation
After running functions inspect myFunction
, I got following output.
Warning: You're using Node.js v10.6.0 but the Google Cloud Functions runtime is only available in Node.js 6 and Node.js 8. Therefore, results from running emulated functions may not match production behavior.
Debugger for app listening on port 9229.
I assume debugging should work now. Open myFunction in the browser (e. g. http://localhost:8010/my-project/us-central1/myFunction/) works fine.
Now I'm struggling. What do I have to do to connect the IDE to the debugger or the debugger to the IDE? I have no clue how debugging works.
Expected result: I want to open the function in Chrome Browser following by pausing on the break points in the WebStorm IDE.
Thanks for helping in advance ;)
UPDATE 2020:
As of firebase-tools v7.11.0 the Firebase emulator allows debugging of hosted functions with the --inspect-functions
flag. This has many advantages over using functions-framework as described below. See this answer for details.
ORIGINAL ANSWER:
Configuring WebStorm to debug a Firebase function can be confusing because there are a couple of different ways to run Firebase functions locally.
Here's what works for me:
npm install --save-dev @google-cloud/functions-framework
Node.js
debug configuration
node_modules/@google-cloud/functions-framework/build/src/index.js
--target=<your-function-name>
It should look something like this:
(In my example, I'm also specifying the --port
switch to set the port the function will listen on).
After that, running Run | Debug | Debug Function
from the WebStorm menu will load up your function and hit any breakpoints you've set.
Add this npm run script to package.json
:
"dev": "npm run build && firebase emulators:start --only functions --inspect-functions 10001 & tsc --watch"
& tsc --watch
from abovenpm run dev
to launch the emulators, or create a npm
run config dedicated for this in WebStorm. You'll need to launch this using WebStorm or manually before the next step, everytime, unless you use compound run configurations (see last section)Attach to NodeJS/ Chrome
, and update the portCompound
run configuration, which starts all the things you might need: e.g. I have 4 things running at the same time, my web app client in React, 1 for the NextJS server which serves/ build the react app, my firebase functions (just to run it), and the firebase debugging run configuration (just to debug it).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With