Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(dev): autorestart frontend unit when vite crashes at startup (#78088)

Thomas Obermüllerf526370e2a1a
diff --git a/bin/start-frontend b/bin/start-frontend
index b2efcc1cf482..9b42233eab32 100755
--- a/bin/start-frontend
+++ b/bin/start-frontend
@@ -89,6 +89,12 @@ pnpm --filter=@posthog/frontend... install
# turbo is running (a foreground child would keep bash blocked in turbo's own
# wait, delaying signal handling). `wait` returns when turbo exits or when a
# trapped signal interrupts it, at which point shutdown() reaps the subtree.
+#
+# start-vite runs concurrently with --kill-others-on-fail so a Vite crash (e.g.
+# exit 127 when a dep relink races startup) tears down the toolbar watcher too,
+# letting this script exit non-zero instead of hanging while the watcher lives
+# on. That non-zero exit is what the process manager needs to see to autorestart
+# the frontend unit — without it a crashed Vite leaves the unit stuck pending.
bin/turbo --filter=@posthog/frontend start-vite &
turbo_pid=$!
wait "$turbo_pid"
diff --git a/frontend/package.json b/frontend/package.json
index c36f5041bbac..40ffae71d6e1 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -48,7 +48,7 @@
"check-toolbar-csp-eval": "node ./bin/check-toolbar-csp-eval.mjs",
"check-toolbar-graph": "node ./bin/check-toolbar-graph.mjs",
"check-toolbar-size": "node ./bin/check-toolbar-size.mjs",
- "start-vite": "pnpm build:products && concurrently -n VITE,TOOLBAR -c green,magenta \"vite --host 0.0.0.0\" \"pnpm watch:toolbar\"",
+ "start-vite": "pnpm build:products && concurrently --kill-others-on-fail -n VITE,TOOLBAR -c green,magenta \"vite --host 0.0.0.0\" \"pnpm watch:toolbar\"",
"watch:toolbar": "node ./bin/build-toolbar.mjs --dev",
"mobile-replay:web:schema:build:json": "ts-json-schema-generator -f ./tsconfig.json --path 'node_modules/posthog-js/dist/rrweb-types.d.ts' --type 'eventWithTime' --expose all --no-top-ref --no-type-check --out ./src/scenes/session-recordings/mobile-replay/schema/web/rr-web-schema.json && oxfmt ./src/scenes/session-recordings/mobile-replay/schema/web/rr-web-schema.json",
"mobile-replay:mobile:schema:build:json": "ts-json-schema-generator -f ./tsconfig.json --path './src/scenes/session-recordings/mobile-replay/mobile.types.ts' --type 'mobileEventWithTime' --expose all --no-top-ref --no-type-check --out ./src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json && oxfmt ./src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json",