Fix #62: declare picocolors and @clack/core as runtime dependencies#68
Open
hyericlee wants to merge 1 commit into
Open
Fix #62: declare picocolors and @clack/core as runtime dependencies#68hyericlee wants to merge 1 commit into
hyericlee wants to merge 1 commit into
Conversation
The CLI bundle imports picocolors and @clack/core directly (the custom interactive file selector in file-selector-with-header.ts), but neither was declared in the published root package.json. esbuild keeps all npm packages external (packages: 'external'), so both must exist at runtime. They only resolved by accident, as hoisted transitive deps of @clack/prompts. In strict / non-hoisting installs (pnpm, or npm under a version conflict) they land nested under @clack/prompts and become unreachable from opkg's own chunk: Cannot find package 'picocolors' imported from .../packages/cli/dist/chunk-*.js Declaring both as direct dependencies puts them on opkg's resolution path regardless of hoisting. @clack/core is pinned to ^1.0.1 to dedupe with @clack/prompts (which pins it exactly), avoiding a second copy of the AutocompletePrompt base class we subclass. Verified with a non-hoisting repro (npm --install-strategy=nested): the exact #62 error before, clean after. Type-check clean, 123/123 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Fixes #62 —
opkg addcrashes at startup on some installs with:Reported on Homebrew/macOS and linuxbrew (Node v25). Workaround was a manual
npm i -g picocolors.Root cause
The CLI bundle imports
picocolorsand@clack/coredirectly — they power the custom interactive file selector (packages/cli/src/utils/file-selector-with-header.ts:@clack/core'sAutocompletePromptbase class +picocolorsfor coloring). esbuild builds withpackages: 'external', so every npm import stays external and must be present at runtime.Neither was declared in the published root
package.json. npm only readspackage.json, never the bundled JS, so it never installed them on opkg's behalf — they only appeared as hoisted transitive deps of@clack/prompts. Whether opkg's own chunk could resolve them came down to hoisting luck:node_modules/picocolors→ resolves → works (most npm installs + dev, which is why it went unnoticed).@clack/prompts/node_modules/picocolors, off opkg's resolution path → crash.This is a classic phantom-dependency bug, and it had drifted twice (
picocolorsand@clack/core).Fix
Declare both in the root
dependencies:@clack/coreis pinned to^1.0.1to dedupe with@clack/prompts(which pins it exactly1.0.1), avoiding a second copy of theAutocompletePromptbase class we subclass.Verification
Repro packs the actual build and installs it with
npm install --install-strategy=nested(the canonical way to expose a phantom dep — no hoisting to mask it):opkg addexits 1 with the verbatim Error with "picocolors" when adding a Claude project #62 error; picocolors unreachable.node_modules/opkg/node_modules/{picocolors,@clack/core};opkg addexits 0 and runs into real logic.Also:
npm run buildclean,tsctype-check clean, 123/123 tests pass.Follow-up (not in this PR)
A build-time guard that diffs the built bundle's external imports against the declared root deps (fail on under-declaration) would catch this class of bug in CI — recommended, since dev hoisting always masks it.
🤖 Generated with Claude Code