Skip to content

Can't debug with firebase tools 6.10.0 in vs code due to unverified breakpoints #1360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ke-nzo opened this issue Jun 2, 2019 · 35 comments · Fixed by #1798
Closed

Can't debug with firebase tools 6.10.0 in vs code due to unverified breakpoints #1360

ke-nzo opened this issue Jun 2, 2019 · 35 comments · Fixed by #1798

Comments

@ke-nzo
Copy link

ke-nzo commented Jun 2, 2019

[REQUIRED] Environment info

firebase-tools: 6.10.0

Platform:macOs, Windows

[REQUIRED] Test case

launching attach to debug from launch.json, breakpoint will result all unverified with no possibility to stop in

[REQUIRED] Steps to reproduce

"version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach by Process ID",
      "processId": "${command:PickProcess}"
    }
  ]
}

simply run Attach by Process ID, and breakpoints will result in grey unverified.

[REQUIRED] Expected behavior

breakpoint must to remain red for stop in and debug

[REQUIRED] Actual behavior

breakpoint remain grey after debug launched

i'd like to add that i have tested debug with firebase-tools 6.3.0 and attach to process perfectly work. with 6.10.0 doesn't.

@google-oss-bot
Copy link
Contributor

This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

@thechenky
Copy link
Contributor

@vincy261 this seems like an issue with VSCode and not firebase tools. I would try asking on channels like StackOverflow to get the support you need.

@ke-nzo
Copy link
Author

ke-nzo commented Jun 3, 2019

HI @thechenky , i have tested debug with firebase-tools 6.3.0 and attach to process perfectly work. with 6.10.0 doesn't. Same VS code

@samtstern
Copy link
Contributor

Thanks @vincy261. I think @abeisgoat knows more about this. The new emulator (in versions 6.9.0 and above) runs the functions in a separate process which probably needs to expose some more information to be debuggable.

@abeisgoat
Copy link
Contributor

Hey @vincy261, can you provide a detailed step-by-step example of how to reproduce this? I have no familiarity with VS Code or how the debugging works, so I'll need something like...

  1. Make a new folder
  2. Put XXX in index.js
  3. Put a breakpoint by doing X
  4. Run the code by doing this...
  5. Etc, etc

I have no idea what's expected so I can't really help until I have that info. As Sam said, we did switch how we run functions, so it's expected that this could break.

@abeisgoat abeisgoat added the Needs: Author Feedback Issues awaiting author feedback label Jun 3, 2019
@ke-nzo
Copy link
Author

ke-nzo commented Jun 3, 2019

Hi @abeisgoat , sure i can, so:

  1. Create a new firebase project with typescript
  2. Write a simple index.ts and export your cloud function testFunction and set it in the firebase.json
import * as express from 'express';
import * as functions from 'firebase-functions';

const app = express();

app.head('/', (req, res) => res.sendStatus(204))

app.get('/timestamp', (req, res) => {
  res.send(`${Date.now()}`);
})

export const testFunction = functions.https.onRequest(app);

console.log('started')
  1. add this to the launch.json (launch json is the debug settings file for VS code integrated debug tool usually the third icon on the side bar menu)
"version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach by Process ID",
      "processId": "${command:PickProcess}"
    }
  ]
}     
  1. run tsc (typescript compiler) and the local emulator
tsc
firebase serve --only functions
  1. now press F1 it will open the command menu and type: debug: Attach by Process ID
    usually is the first process. Now your bottom bar from blue should turn orange

  2. at this point you will notice that if you put a breakpoint on:

res.send(`${Date.now()}`);

the breakpoint doesn't turn red but grey and it will say "unverified breakpoint" thus calling timestamp endpoint in the browser it won't stop on the line.

instead repeat the test with [email protected] (or at least prior to 6.9.0) and it will work!

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Jun 3, 2019
@abeisgoat
Copy link
Contributor

Fantastic, thanks for the thorough and quick response, I'll take a look at this when I get some time and report back!

@abeisgoat
Copy link
Contributor

So I've looked into this a bit and it seems like it's going to be tricky. If we changed how the emulator works to solve #1353 it would also make this easier, so this is an argument in favor of changing that system.

@sultanmyrza
Copy link

6.3.0

Hi @abeisgoat , sure i can, so:

  1. Create a new firebase project with typescript
  2. Write a simple index.ts and export your cloud function testFunction and set it in the firebase.json
import * as express from 'express';
import * as functions from 'firebase-functions';

const app = express();

app.head('/', (req, res) => res.sendStatus(204))

app.get('/timestamp', (req, res) => {
  res.send(`${Date.now()}`);
})

export const testFunction = functions.https.onRequest(app);

console.log('started')
  1. add this to the launch.json (launch json is the debug settings file for VS code integrated debug tool usually the third icon on the side bar menu)
"version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach by Process ID",
      "processId": "${command:PickProcess}"
    }
  ]
}     
  1. run tsc (typescript compiler) and the local emulator
tsc
firebase serve --only functions
  1. now press F1 it will open the command menu and type: debug: Attach by Process ID
    usually is the first process. Now your bottom bar from blue should turn orange
  2. at this point you will notice that if you put a breakpoint on:
res.send(`${Date.now()}`);

the breakpoint doesn't turn red but grey and it will say "unverified breakpoint" thus calling timestamp endpoint in the browser it won't stop on the line.

instead repeat the test with [email protected] (or at least prior to 6.9.0) and it will work!

when install [email protected] it gives warning

sudo npm i -g [email protected]
npm WARN deprecated @google-cloud/[email protected]: Deprecating in favor of the Functions Framework and firebase-tools. See googlearchive/cloud-functions-emulator#327
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js

@google-cloud/[email protected] postinstall /usr/local/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator
node scripts/upgrade-warning

If you're using the Emulator via the Firebase CLI, you can
disregard this message.

If you're upgrading @google-cloud/functions-emulator, these
are the recommended upgrade steps:

  1. Stop the currently running emulator, if any:

    functions stop
    
  2. Uninstall the current emulator, if any:

    npm uninstall -g @google-cloud/functions-emulator
    
  3. Install the new version of the emulator:

    npm install -g @google-cloud/functions-emulator
    

If you have trouble after upgrading, try deleting the config
directory found in:

~/.config/configstore/@google-cloud/functions-emulator

Then restart the emulator. You can also check for any renegade
Node.js emulator processes that may need to be killed:

ps aux | grep node

@vongohren
Copy link

@vincy261 so you are saying you are getting the connection up, but the breakpoints are not verified?

I would love to see some documentation on how to set it up, maybe towards the chrome debugger as well. Not just VS code

@sultanmyrza not sure why you are posting stuff about a deprecated library?

@goleary
Copy link

goleary commented Nov 20, 2019

as @jimmont mentioned on #517
you can use https://www.npmjs.com/package/ndb to place breakpoints in your firbase functions code.

I simply use ndb yarn serve.

Also, I've only tested in on HTTPS functions so far.

@GorvGoyl
Copy link

@goleary hey, i followed the steps but that just opens the ndb window. debugging session doesn't start. are there any additional steps to follow?

@samtstern
Copy link
Contributor

This has been implemented and will be included in the next release.

@vongohren
Copy link

@samtstern are there any documentation on this?

@samtstern
Copy link
Contributor

samtstern commented Dec 12, 2019 via email

@vongohren
Copy link

@samtstern coolio, great work!

@goleary
Copy link

goleary commented Dec 12, 2019

@JerryGoyal sorry for the delayed response. You're right, you might as well just use ndb in the folder and then start the debugging session by hitting play on one of the scripts on the bottom left:
image

@GorvGoyl
Copy link

@samtstern I upgraded to 7.10.0, updated the launch.json to

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach",
      "port": 9229,
      "restart": true,
      "skipFiles": [
        "<node_internals>/**"
      ]
    }
  ]
}

and tried attaching debugger to firebase emulators:start and also firebase functions:shell but issue remains the same:
image

Am I missing something here?

@samtstern
Copy link
Contributor

@JerryGoyal 7.10.0 is the current release. This will be included in the next release, so 7.11.0 is the likely version number.

@fabianotavallini
Copy link

Version 7.11.0 is now released and introduces breakpoint debugging with the command:

firebase emulators:start --inspect-functions

Then you can attach the debugger to port 9229 (default)

@johngtb
Copy link

johngtb commented Jan 8, 2020

Version 7.11.0 is now released and introduces breakpoint debugging with the command:

firebase emulators:start --inspect-functions

Then you can attach the debugger to port 9229 (default)

Perfect!
Is there a way around the 60s timeout while debugging with --inspect-functions?

Error: Function timed out.
at Timeout._onTimeout (/home/john/.nvm/versions/node/v12.14.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:670:23)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)

@samtstern
Copy link
Contributor

@johngboutros that's a good feature request and I could see a few ways of achieving it:

a) Disable timeouts entirely in debug mode
b) Disable the timeout counter while a breakpoint is active
c) Other??

Would you mind filing a new issue to discuss?

@otri
Copy link

otri commented Jan 14, 2020

A bit of documentation about this would be really helpful on the Firebase site tutorials.
Trying to run with $ firebase serve did not run my npm script 'serve'

Instead I needed to go into my functions folder, and run npm directly with:
$ npm run-script serve

My functions/package.json script for serve looks like this now:
"serve": "tsc -w | firebase emulators:start --inspect-functions",
This allows watching for TypeScript changes, and starting up emulation with debugging.
This is super helpful when actively developing code on your local machine! Life is so much better now.

@samtstern
Copy link
Contributor

@otri firebase serve does not run your npm serve script, it's a command in the CLI that starts up a local Hosting server.

A common point of confusion (which I agree needs better docs) is the overlap between serve and emulators:start. We intend for emulators:start to replace serve completely so for now your approach looks good.

@avaines
Copy link

avaines commented Mar 25, 2020

After a good few hours of faffing about, I found this thread and have confirmed what @otri has described above.

I have added a 'debug' entry to my functions/packages.json as i am not using TypeScript mine looks like this:
"scripts": { "serve": "firebase serve --only functions", "debug": "firebase emulators:start --inspect-functions", },

VSCode's launch.json now looks like this;
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Attach", "port": 6000 } ] }

If I launch my application from the terminal in VSCode itself the debugger attaches automatically.
cd functions & npm run debug

Whilst this does not fix the issue using firebase serve it is a suitable work around (for some of us at least) for local development until this is resolved properly.

@samtstern
Copy link
Contributor

@n3rden firebase serve will not be changed to have this capability. You can serve both your hosting and functions code using emulators:start and that is the preferred method going forward.

@avaines
Copy link

avaines commented Mar 25, 2020

Going forward I appreciate, but at present that method doesn't seem to work with breakpoints.

@otri
Copy link

otri commented Mar 25, 2020 via email

@samtstern
Copy link
Contributor

@n3rden if your breakpoints aren't working can you file a new issue? We will dig into it.
@otri I agree, those steps are needed to make this a better experience. Thank you for the tips.

@quantuminformation
Copy link

At the risk of sounding stupid if functions are running on

✔ functions: functions emulator started at http://localhost:5002

Then my local endpoint is just this change?
image

@samtstern
Copy link
Contributor

samtstern commented May 11, 2020

@quantuminformation a local function would be at a URL like this:
http://localhost:5002/PROJECTID/us-central1/FUNCTIONNAME

But a deployed function would be here:
https://us-central1-PROJECTID.cloudfunctions.net/FUNCTIONNAME

In the future please file new issues if you have new questions.

@quantuminformation
Copy link

Sure, thanks for clearing this up

@lborgman
Copy link

lborgman commented May 19, 2020

When trying to use "firebase emulators:start" it did not work. I notice two things:

  1. The docs at https://firebase.google.com/docs/rules/emulator-setup says I should use the latest Node.js. Is that correct?

  2. The docs point me to https://www.oracle.com/java/technologies/javase-downloads.html while the CLI said I should go to https://openjdk.java.net/install/. Which one is correct? (The downloaded zip files for Win64 are obviously different with different sha256.)

@samtstern
Copy link
Contributor

@lborgman

  1. You should use Node.js 10, I will update the docs.
  2. Any version of Java will work, but thank you for showing that discrepancy,

@samtstern
Copy link
Contributor

I am locking this issue as it references a fixed bug and future developers should file new issues

@firebase firebase locked as resolved and limited conversation to collaborators May 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.