简体   繁体   English

我在 VScode 中使用 JS,我试图通过提示 cmd 获取用户输入,但它不起作用。 我已经安装了 prompt-sync

[英]I'm using JS in VScode and I'm trying to take user input through prompt cmd, but it's not working. I've already installed prompt-sync

I'm trying to write a simple code to take input from the user using the prompt cmd with the Node.js debugger in VScode, but nothing appears on the console, as if the code is forever running.我正在尝试编写一个简单的代码来使用提示 cmd 和 VScode 中的 Node.js 调试器从用户那里获取输入,但是控制台上什么也没有出现,就好像代码永远在运行一样。

What should I do?我应该怎么办?

I've already installed prompt-sync via Command Prompt using: npm install prompt-sync .我已经通过命令提示符安装了 prompt-sync 使用: npm install prompt-sync

Also, I used const prompt = require('prompt-sync')();另外,我使用const prompt = require('prompt-sync')(); as recommended by the README.md within the prompt-sync documentation.按照 prompt-sync 文档中 README.md 的建议。

However, when I write然而,当我写

const name = prompt('Whats your name? ');
console.log(`${name}`)

nothing happens on the DEBUG CONSOLE and the code never stops running. DEBUG CONSOLE 上没有任何反应,代码永远不会停止运行。

I had the same problem and solved adding我遇到了同样的问题并解决了添加

"console": "integratedTerminal"

to the launch.json in VSCode到 VSCode 中的 launch.json

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

相关问题 我无法在 Visual Studio 中安装提示同步 - I cant install prompt-sync in visual studio 如何使用 prompt-sync 获取 1 keypress 的值? - How can I use prompt-sync to get the value of 1 keypress? 使用换行符时,Node.js提示同步会重复提示 - Node.js prompt-sync repeats prompt when using newline characters 我正在学习 webpack 并且我正在尝试进行 api 调用,但它不起作用。 这是我的代码 - I'm learning webpack and I'm trying to make an api call, but it's not working. Here's my code 我正在尝试提出问题提示,但由于语法错误,它不会在提示中加载 - I'm trying to make a question prompt, but It wont load in the prompt due to syntax error 我正在尝试通过添加和删除已设置样式但无法正常工作的活动 class 来创建切换按钮 - I'm trying to create toggle button by adding and removing active class that I've already styled but it wasn't working node.js:使用 readline 从文件中获取输入并在 windows 命令提示符中处理 I/O - node.js: take input from file using readline and process I/O in windows command prompt 我正在尝试使用 while 循环来获取用户输入并插入数组 Javascript - I'm trying to use a while loop to take user input and insert into an array Javascript 找不到模块“提示同步” - Cant find module 'prompt-sync' 无法找到模块“提示同步” - Unable to find module 'prompt-sync'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM