TurboRepo启动React开发服务器后立即退出问题求助
TurboRepo启动React开发服务器后立即退出的问题
我用pnpm搭建了TurboRepo环境,尝试通过命令npx turbo run start --filter=testclient启动testclient客户端的React前端,执行后输出如下:
• Packages in scope: testclient • Running start in 1 packages testclient:start: cache bypass, force executing 4ef91202eb77e2b8 testclient:start: testclient:start: > testclient@0.0.1 start /Users/me/frontend/frontend-core/clients/testclient testclient:start: > node node_modules/react-scripts/bin/react-scripts.js --max-old-space-size=4096 start testclient:start: testclient:start: ℹ 「wds」: Project is running at http://192.168.0.54/ testclient:start: ℹ 「wds」: webpack output is served from testclient:start: ℹ 「wds」: Content not from webpack is served from /Users/me/frontend/frontend-core/clients/testclient/public testclient:start: ℹ 「wds」: 404s will fallback to / testclient:start: Starting the development server... testclient:start: Tasks: 1 successful, 1 total Cached: 0 cached, 1 total Time: 2.339s
可以看到TurboRepo成功启动开发服务器后随即退出,没有保持服务器运行。
我的相关配置如下:
/turbo.json:
{ "$schema": "https://turborepo.org/schema.json", "pipeline": { "start": { "cache": false }, ... }
/pnpm-workspace.yaml:
packages: - 'packages/*' - 'clients/**' - '!**/tests/**'
/package.json:
{ "private": true, "workspaces": [ "clients/*", "packages/*" ], "scripts": { // 根目录没有start脚本,只有/clients下的包有该脚本 ... }
/clients/testclient/package.json(包含start脚本):
{ "name": "testclient", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-scripts/bin/react-scripts.js --max-old-space-size=4096 start", ... }
执行npx turbo run build --filter=testclient可以正常完成构建,而且直接用npm start --prefix=clients/testclient也能正常启动开发服务器,输出如下:
Compiled with warnings. /Users/me/frontend/frontend-core/packages/frontend-core/dist/frontend-core.css (/Users/me/frontend/frontend-core/node_modules/.pnpm/css-loader@3.4.2_webpack@4.42.0/node_modules/css-loader/dist/cjs.js??ref--6-oneOf-3-1!/Users/me/frontend/frontend-core/node_modules/.pnpm/postcss-loader@3.0.0/node_modules/postcss-loader/src??postcss!/Users/me/frontend/frontend-core/packages/frontend-core/dist/frontend-core.css) Warning (14:63200) end value has mixed support, consider using flex-end instead Search for the keywords to learn more about each warning. To ignore, add // eslint-disable-next-line to the line before.
请问为什么TurboRepo启动服务器后会立即退出并终止进程?
原因及解决方法
TurboRepo默认将任务视为一次性任务,执行完成后就会退出;而React的start脚本是长期运行的开发服务器,属于持续性任务,需要明确告知TurboRepo保持进程存活。
解决方法1:修改turbo.json配置
在turbo.json的start流水线配置中添加persistent: true字段,标记该任务为持续运行类型:
{ "$schema": "https://turborepo.org/schema.json", "pipeline": { "start": { "cache": false, "persistent": true }, ... }
解决方法2:临时启用持久化参数
执行命令时直接添加--persistent参数,临时让TurboRepo保持进程运行:
npx turbo run start --filter=testclient --persistent
配置或参数生效后,再执行启动命令,TurboRepo就会维持开发服务器的进程,不会自动退出。
内容的提问来源于stack exchange,提问作者usbToaster
相关产品推荐
相关产品推荐

