fix(cli): load undici after the Node version preflight - #1207
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(cli): load undici after the Node version preflight#1207posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
A static `import ... from 'undici'` in bin.ts runs before any statement in the entry module, so undici loaded before the Node version check could run. On Node below 22.10 that load throws `webidl.util.markAsUncloneable is not a function`, and users saw that stack instead of the upgrade message. Load undici with a dynamic import after the preflight passes. Add a smoke-test check that fails the build if undici returns to the static import graph. Generated-By: PostHog Desktop Task-Id: 29ffcd2b-0ca5-48c6-a645-5172d0e37c9c
🧙 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
Test against a Context Mill branch:
Add 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
npx @posthog/wizardget a rawTypeError: webidl.util.markAsUncloneable is not a functionstack instead of the friendly upgrade message. The wizard is the onboarding entry point, so each one is a person who cannot finish setup and is not told why. First seen shortly after 2.72.0 reached npm, with no occurrences in the preceding two weeks.bin.tsimportedundicistatically. ESM evaluates every static import before the first statement of the module, so undici loaded before thesatisfies(process.version, '>=22.22.0')preflight could run. The preflight comment says it exists to stop exactly this crash, but import hoisting made it unreachable.tsdown.config.ts, so npx installs undici 8.5.0 next to whatever Node the user has.Changes
await import('undici')after the preflight passes, so the version guard is genuinely the first thing that runs. ThesetGlobalDispatcher(new Agent({ allowH2: false }))workaround and itsTODO(#1198)context are unchanged, just relocated.dist/bin.js. CI runs one modern Node, so this is the check that survives the next dependency bump.TypeError: webidl.util.markAsUncloneable is not a functionPHW_CLI_NODE_VERSION, exit 1Test plan
Built and ran the compiled binary on both runtimes.
Node 20.19.0, before and after
Before:
After:
Exit code 1.
node dist/bin.js --helpprints the command list as before.pnpm build(runs the smoke test and the warlock smoke test) passes.dist/bin.js, and passes on the real build.npx vitest run: 2601 tests pass, 161 files.pnpm lint: 0 errors.pnpm typecheck: 27 errors before and after this change, none inbin.ts.LLM context
Written by a PostHog self-driving agent.
bin.tsdid not need splitting into a preflight shim plus a lazily imported main module. That split would make the guard structurally first for every dependency, not just undici, and is the deeper fix if another dep ever crashes on load.Created with PostHog Desktop from this inbox report.