You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js inquirer库脚本运行时终端提示重复显示,求解决方案

解决Inquirer提示重复显示的问题

下面是几种可行的解决思路:

  • 切换原生终端运行
    部分IDE内置终端或特殊终端环境存在TTY交互异常,会导致Inquirer重复输出提示。建议在系统原生终端(如Windows PowerShell、macOS终端)中用node命令直接执行脚本。

  • 更新/重装Inquirer
    版本兼容性问题可能引发该异常,执行以下命令更新到最新稳定版:

npm update inquirer

或彻底重装:

npm uninstall inquirer && npm install inquirer
  • 修正脚本错误并规范字段
    你的代码catch块里存在拼写错误(erorr应为error),虽不是提示重复的直接原因,但会导致错误处理异常。同时建议将name字段改为无空格的标识符格式,避免潜在解析问题,修正后的代码如下:
import inquirer from "inquirer"

inquirer
  .prompt([{
        name: "kingOfFrance",
        message: "Who is the king of France"
    }
  ])
  .then((answers) => {
    console.log("Nothing should be printed.")
  })
  .catch((error) => {
    if (error.isTtyError) {
        console.log(error)
    } else {
        console.log(error)
    }
  });
  • 检查脚本执行方式
    确认是否使用了nodemon等自动重启工具,这类工具可能导致脚本被重复执行。如果是,改用node your-script-name.js直接运行脚本。

内容的提问来源于stack exchange,提问作者F.I.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 14:57:12