使用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" }
验证步骤
- 重新执行
bun build确保dist目录有最新编译产物 - 运行
bun start,此时项目会正常启动,不会再出现重复路径的循环输出
内容的提问来源于stack exchange,提问作者michael25
相关产品推荐
相关产品推荐

