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);
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"
}
]
}
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