Skip to content

fix: bundle semver to prevent npx/bunx cache startup crashes#679

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/bundle-semver-startup-crash
Draft

fix: bundle semver to prevent npx/bunx cache startup crashes#679
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/bundle-semver-startup-crash

Conversation

@posthog

@posthog posthog Bot commented Jun 17, 2026

Copy link
Copy Markdown

Problem

Users running npx/bunx @posthog/wizard occasionally hit an instant, unrecoverable startup crash that blocks PostHog onboarding for that session. Error tracking captured two first-seen issues of the same class: Cannot find module './ranges/intersects' (npx cache, Windows) and Cannot find module './functions/sort' (bunx cache, macOS), both thrown from node_modules/semver/index.js before any wizard code runs.

Why: semver's entry file eagerly require()s its entire ./functions/* and ./ranges/* submodule tree at load. Because the build set skipNodeModulesBundle: true, semver was left external and extracted on the user's machine by the package runner. When that extraction is corrupted/partial (a known failure mode when antivirus or a concurrent npx/bunx run interrupts it), the eager require throws MODULE_NOT_FOUND immediately — regardless of which exports the wizard actually uses.

Changes

Force-bundle semver into the wizard output via deps.alwaysBundle, so a corrupted runtime install can no longer surface a missing-submodule crash. This eliminates the whole error class across both npx and bunx in one build-config change.

  • skipNodeModulesBundle and alwaysBundle are mutually exclusive in tsdown, so this migrates to the default behavior (externalize declared production dependencies) and bundles only semver.
  • semver is dependency-free, so the bundle stays self-contained; all other runtime deps (react, zod, ink, axios, posthog-node, …) remain external.

Test plan

  • pnpm build succeeds; verified semver is inlined into the output and no bare import/require 'semver' remains, while all other production deps stay external.
  • Reproduced the reported crash by deleting functions/sort.js / ranges/intersects.js from the installed semver (simulating a partial extraction): a bare require('semver') throws MODULE_NOT_FOUND, but node dist/bin.js --version starts cleanly from the bundled copy.
  • pnpm test — 907 tests pass; postbuild smoke test passes.

LLM context

Authored by PostHog Code (Claude) from an error-tracking inbox report.


Created with PostHog Code from an inbox report.

semver's entry file eagerly require()s its entire ./functions/* and ./ranges/*
submodule tree at load. Because the build left semver external
(skipNodeModulesBundle), a corrupted/partial semver tarball in an npx or bunx
cache threw MODULE_NOT_FOUND (e.g. './ranges/intersects', './functions/sort')
before any wizard code ran — an instant, unrecoverable startup crash.

Force-bundle semver into the output via deps.alwaysBundle so a corrupted runtime
install can no longer surface a missing-submodule crash. semver is
dependency-free, so the bundle stays self-contained; all other deps remain
external. skipNodeModulesBundle and alwaysBundle are mutually exclusive in
tsdown, so this migrates to the default behavior (externalize declared
production deps) and bundles only semver.

Generated-By: PostHog Code
Task-Id: 82411704-9a3d-4c1e-ac18-004f40343691
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci error-tracking-upload-source-maps
  • /wizard-ci misc
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci error-tracking-upload-source-maps/android
  • /wizard-ci error-tracking-upload-source-maps/cicd-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-nested-docker-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-github-actions-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-gitlab-node-raw
  • /wizard-ci error-tracking-upload-source-maps/cicd-ssh-vps-node-raw
  • /wizard-ci error-tracking-upload-source-maps/flutter
  • /wizard-ci error-tracking-upload-source-maps/ios
  • /wizard-ci error-tracking-upload-source-maps/next
  • /wizard-ci error-tracking-upload-source-maps/next-no-posthog
  • /wizard-ci error-tracking-upload-source-maps/node-raw
  • /wizard-ci error-tracking-upload-source-maps/node-rollup
  • /wizard-ci error-tracking-upload-source-maps/node-rollup-typescript-plugin
  • /wizard-ci error-tracking-upload-source-maps/node-webpack
  • /wizard-ci error-tracking-upload-source-maps/nuxt-3-6
  • /wizard-ci error-tracking-upload-source-maps/nuxt-4-3
  • /wizard-ci error-tracking-upload-source-maps/react-native
  • /wizard-ci error-tracking-upload-source-maps/react-vite
  • /wizard-ci error-tracking-upload-source-maps/rust
  • /wizard-ci misc/quack-quack
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants