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

如何阻止Parcel自动清除控制台日志?

解决Parcel自动重载时清除console.log的问题

针对你遇到的Parcel开发模式下自动重载后清空控制台日志的问题,可通过以下两种方式解决:

方式一:修改启动命令,添加环境变量

在package.json的scripts字段中,给start命令加入环境变量来禁用日志清除行为:

适用于macOS/Linux系统:

"scripts": {
  "start": "PARCEL_HMR_CLEAR_LOG=false parcel index.html",
  "build": "parcel build index.html"
}

适用于Windows系统:

"scripts": {
  "start": "set PARCEL_HMR_CLEAR_LOG=false && parcel index.html",
  "build": "parcel build index.html"
}

方式二:添加Parcel配置(推荐)

直接在package.json中新增parcel配置字段,通过配置项关闭热重载时的日志清除:

修改后的完整package.json如下:

{
  "name": "forkify",
  "version": "1.0.0",
  "description": "",
  "default": "index.html",
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build index.html"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "@parcel/transformer-sass": "^2.7.0",
    "parcel": "^2.7.0"
  },
  "parcel": {
    "hmrOptions": {
      "clearLog": false
    }
  }
}

完成配置修改后,重新执行npm start,修改JS文件保存触发页面重载时,控制台的console.log输出就不会被清除了。

内容的提问来源于stack exchange,提问作者MinhSu - Justin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 07:50:28