Inquirer.js: Integration with vscode debugger

Created on 21 Feb 2018  路  11Comments  路  Source: SBoudrias/Inquirer.js

Are there any special instructions to get this to work with a debugger (in particular, Visual Studio Code)? When launching via the debugger, I don't see any console output from inquirer.prompt().

Most helpful comment

Example of launch.json with terminal that supports tty:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "With TTY",
      "program": "<path to program>",
      "console": "integratedTerminal"
    }
  ]
}

This works really well for my use cases.

All 11 comments

Chances are that VS studio doesn't have full TTY support. I don't think you'd be able to get this working outside your terminal (or until VS add full TTY support)

And how do you debugger ? now. console.log ?

I use the chrome devtool connected to the node remote debug process. This probably works similar with vs code

Ran into this as well, added "console": "integratedTerminal" to my launch configuration to change from the debugger repl to full terminal and was able to debug inquirer apps using vscode debugger.

vscode docs: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_node-console

May be worth mentioning in a FAQ or the README :)

If anyone want to send launch.json config for the project. I'll be happy to help merge it.

Example of launch.json with terminal that supports tty:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "With TTY",
      "program": "<path to program>",
      "console": "integratedTerminal"
    }
  ]
}

This works really well for my use cases.

https://tahirhassan.blogspot.com/2019/05/inquirer-debugging-in-visual-studio-code.html

add this line "console": "externalTerminal" on your "configurations"

    "version": "0.2.0",
    "configurations": [

        {
            "type": "node",
            "request": "launch",
            "name": "鍚姩绋嬪簭",
            // "program": "${workspaceFolder}/bin/test",
            "program": "${workspaceFolder}/bin/cli",
            "args": [
                "init",
                "aasas",
            ],
            "console": "externalTerminal" 
        },
    ],

and prompt log will be output on externalTerminal

@sqren Thank you so much! 馃憤

I'll close the ticket as @sqren instructions appears to work properly.

Thanks!

I recognize this ticket was closed, but I'm a little confused about what the expected outcome from using the integrated Terminal should be.

When I am debugging using the integratedTerminal, I _am_ able to see the prompts and interact, however, in my case, I seem to have no visibility into the state of the application. It's as if the program has already exited.

Screen Shot 2020-10-11 at 4 54 03 PM

In the screen shot, you can see I have the prompt from my CLI available, the debugger has paused the process, but if you look at the left nav - there's nothing in variables, the call stack _only_ has the debugger, etc.

What am I missing? Since I'm using Inquirer in an async method, shouldn't I be able to step through and see the answers as they come _back_ from stdin?

FWIW - the question I'm currently debugging is here (summarized below):

import { prompt } from "inquirer"
import dayjs from "dayjs"
import kebabCase from "lodash.kebabcase"
import {
    ConfigurationKeys,
    DocumentStages,
    FrontmatterKeys,
    IFrontmatter,
} from "../utils"

interface ISolicitNoteMetadata {
    title?: string
    config: Map<ConfigurationKeys, any>
    options: IFrontmatter
}

export async function solicitNoteMetadata({
    title,
    config,
    options,
}: ISolicitNoteMetadata) {
    const defaultDateFmt = config.get(ConfigurationKeys.DEFAULT_DATE_FORMAT)
    const questions = [
        {
            type: "input",
            name: "title",
            message: "What's the title for the note?",
            default: options["title"] || title,
        },
        //...
    ]

    await prompt(questions).then((answers) => {
        options["title"] = answers.title
        //...
    })
}

In case someone will be looking for Intellij WebStorm debug config. You need to enable a registry flag first as described in this ticket to capture user input in terminal. Then create normal Node.js "Run Configuration" and point it to your index.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apierzch picture apierzch  路  4Comments

aydn picture aydn  路  5Comments

christav picture christav  路  5Comments

bapti picture bapti  路  6Comments

aaronshaf picture aaronshaf  路  7Comments