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

使用Bun构建项目后执行bun start出现循环异常求助

Bun项目build后start命令循环重复路径的解决方案

问题原因

你的package.json中start脚本存在递归调用问题:

"start": "bun start dist/index.js"

当运行bun start时,Bun会执行这个脚本,而脚本里的bun start又会再次触发start脚本,同时把dist/index.js作为参数传递。每一次递归调用都会在参数列表里多添加一个dist/index.js,最终出现循环叠加的路径输出。

解决方案

修改start脚本,直接用Bun运行编译后的文件,避免递归调用:

"scripts": {
   "start": "bun dist/index.js",
    "dev": "bun --watch src/index.js",
    "test": "bun test",
    "lint": "bun prettier --write .",
    "build": "bun build src/index.js --outdir ./dist"
  }

验证步骤

  1. 重新执行bun build确保dist目录有最新编译产物
  2. 运行bun start,此时项目会正常启动,不会再出现重复路径的循环输出

内容的提问来源于stack exchange,提问作者michael25

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 03:27:04