fix: bundle semver to prevent npx/bunx cache startup crashes#679
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix: bundle semver to prevent npx/bunx cache startup crashes#679posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
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
🧙 Wizard CIRun 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:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users running
npx/bunx @posthog/wizardoccasionally 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) andCannot find module './functions/sort'(bunx cache, macOS), both thrown fromnode_modules/semver/index.jsbefore any wizard code runs.Why: semver's entry file eagerly
require()s its entire./functions/*and./ranges/*submodule tree at load. Because the build setskipNodeModulesBundle: 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 throwsMODULE_NOT_FOUNDimmediately — 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.skipNodeModulesBundleandalwaysBundleare mutually exclusive in tsdown, so this migrates to the default behavior (externalize declared production dependencies) and bundles only semver.Test plan
pnpm buildsucceeds; verified semver is inlined into the output and no bareimport/require 'semver'remains, while all other production deps stay external.functions/sort.js/ranges/intersects.jsfrom the installed semver (simulating a partial extraction): a barerequire('semver')throwsMODULE_NOT_FOUND, butnode dist/bin.js --versionstarts 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.