3

I encountered a situation where node.js could not be debugged. The application entry file uses Interactive mode. It is with inquirer npm package.

I have used the debug tool of node,it doesn't work.

Here is the code:

const inquirer = require('inquirer');
const commonQuestions = [{...}]; // some code is omitted here
const shortCutQuestions = [{
  type: 'rawlist',
  name: 'cmd',
  message: '请选择快捷命令(直接输入数字进行选择):',
  pageSize: 10,
  default: 0,
  choices: cacheCommands,
}];

const shortCutResolveFunc = ({ cmd }) => {
  updateCommands(cmd);

  try {
    signale.watch(`cmd: ${cmd}`);

    const [globalCmd, ...cmdLineArgs] = cmd.split(' ');

    spawn.sync(globalCmd, cmdLineArgs, { stdio: 'inherit' });
  } catch (err) {
    console.log(pe.render(err));
  }
};

inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));

inquirer
  .prompt(isCommonMode ? commonQuestions : shortCutQuestions)
  .then(isCommonMode ? commonResolveFunc : shortCutResolveFunc);
CC BY-SA 4.0

1 Answer 1

8

Not sure what wasn't working, but was it perhaps that you hadn't configured your Visual Studio Code debugger to use a console other than the internalConsole (which is default).

here's an example of a launch.json configuration that uses the integratedTerminal:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Launch Program",
            "console": "integratedTerminal", // <= the relevant part
            "program": "${workspaceFolder}/main.js"
        }
    ]
}
CC BY-SA 4.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.