Skip to content

debugger (ie. node inspect). watch(<variabe>) says it's not defined, but it is. Am I not using this correctly? #2946

Closed

Description

@DavidTsGit
  • Node.js Version:
    v12.18.3

  • OS:
    macOS 10.15.6

  • Scope (install, code, runtime, meta, other?):
    ???

  • Module (and version) (if relevant):
    ???

New here, and not quite sure the answers to some of the above.

Stepping through my code with node inspect as documented here: https://nodejs.org/docs/latest-v12.x/api/debugger.html

One of the options is:
• watch(expr): Add expression to watch list

Ok, I'm stepping through my code. I'm in the middle of a function called by a constructor function, instantiating/creating an object in a class. There's a bunch of let <variable> = <value> statements. If I go into repl and ask it to tell me the values of those variables (eg. I have one variable di for argument's sake) it reports them correctly. But (outside of repl again) I do watch(di) and it says Uncaught ReferenceError: di is not defined.

I can't imaging this is a bug, or it would have been found and fixed by others long before I came along. Am I using this incorrectly? How do I add a variable or expression to the watch list without getting that not defined error?

I'd appreciate any help. Thanks!

Activity

  1. gireeshpunathil commented on Nov 6, 2020

    @gireeshpunathil
    Member

    @Detnator-Neo - can you provide the program that reproduces this?

  2. gireeshpunathil commented on Dec 9, 2020

    @gireeshpunathil
    Member

    inactive, closing. feel free to re-open if it is outstanding

  3. unixatch commented on Jan 10, 2026

    @unixatch

    @DavidTsGit i dunno if you still use it or even care but when using watch() you need to pass it a string to be able to use it properly like:
    watch("di") instead of watch(di).

    Also you can use console.log() inside it for more information like watch("console.log(di)")

    Source from where i understood it:
    https://github.com/nodejs/node/blob/a327288cc6747cf5e07656a1c45fe2f19e0926ae/lib/internal/debugger/inspect_repl.js#L1085-L1088

    P.S: i think in the help text for node inspect it should show watch("expr") instead of watch(expr) because of this very issue, same with expr(expr), p(expr) and unwatch(expr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions