prompt() 方法在终端中有效,但不能在调试控制台 vscode 中工作

问题描述 投票:0回答:1
"use strict";

const ps = require("prompt-sync");
const prompt = ps();

let base = prompt("base :");
let height = prompt("height:");
let area = (base * height / 2);
console.log(`The area of triangle is ${area}`);

当我在终端(节点文件名.js)中运行它时,代码可以工作。

但是当我在调试控制台中运行它时,我收到此错误:

Uncaught Error Error: ENXIO: no such device or address, open '/dev/tty`

知道为什么吗?

javascript visual-studio-code prompt
1个回答
1
投票

默认情况下,Node.js 程序在 VS 调试控制台中启动,该控制台不支持从终端输入读取。

您可以更改 launch.json 配置,将控制台从默认的

internalConsole
切换为
integratedTerminal
,从而解决问题:

.vscode/launch.json:

"configurations": [
  ...
  ...
  "console": "integratedTerminal"
  ...
]

相关文档:https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_node-console

© www.soinside.com 2019 - 2024. All rights reserved.