简体   繁体   English

如何在 WebStorm 中使用 readline-sync npm 存储库?

[英]How can I use readline-sync npm repository with WebStorm?

I wrote the following code using 'readline-sync' dependency.我使用“readline-sync”依赖编写了以下代码。

var readlineSync = require('readline-sync');
function main() {
    printMenu();
    var userName = readlineSync.question('Please enter your choice:');
    console.log(userName);
}
main();

I ran this code from WebStorm trying to use the WebStorm console window.我从 WebStorm 运行此代码尝试使用 WebStorm 控制台窗口。 I got the error:我得到了错误:

Error: The current environment doesn't support interactive reading from TTY.错误:当前环境不支持从 TTY 交互式阅读。 stty: when specifying an output style, modes may not be set stty:指定输出样式时,可能不会设置模式

When I run it from linux terminal the code works with no error.当我从 linux 终端运行它时,代码可以正常工作。 I understand from the error message that 'readline-sync' cannot work from WebStorm console.我从错误消息中了解到“readline-sync”无法从 WebStorm 控制台工作。 Do you have any idea how to solve it?你知道如何解决它吗?

I found out the answer.我找到了答案。

  1. type in WebStorm terminal: $ node --debug-brk Web storm will give you the port number the debugger is listening to.在 WebStorm 终端中键入: $ node --debug-brk Web Storm 将为您提供调试器正在侦听的端口号。 On my machine it was 5858. Then press 'Ctrl+C'.在我的机器上是 5858。然后按 'Ctrl+C'。

  2. Create a new debugging configuration as the following one:创建一个新的调试配置如下: 在此处输入图片说明

  3. In WebStorm terminal type again: "$ node --debug-brk main.js "在 WebStorm 终端中再次输入:“$ node --debug-brk main.js”

  4. put a breakpoint somewhere.在某处放置一个断点。
  5. Click the debugging icon点击调试图标在此处输入图片说明

Happy Debugging!调试愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM