fix(cli): run bundled wrangler binary instead of npx - #265
Merged
Merged
Conversation
`npx wrangler` resolves whatever wrangler is cached in ~/.npm/_npx for the bare "wrangler" spec (or on PATH), which can be an old version that misreads the modern `assets.directory` config in wrangler.json and fails with "assets.bucket is a required field". Run the wrangler binary bundled with @counterscale/cli's own dependency tree instead, falling back to `npx wrangler` only if resolution fails. Fixes #256
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #265 +/- ##
==========================================
- Coverage 83.90% 82.68% -1.22%
==========================================
Files 55 56 +1
Lines 1882 2010 +128
Branches 518 539 +21
==========================================
+ Hits 1579 1662 +83
- Misses 267 310 +43
- Partials 36 38 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stordahl
marked this pull request as ready for review
September 8, 2026 23:55
Address PR review: the silent npx fallback made a future resolution failure (e.g. wrangler changing its exports map) degrade invisibly back to the bug this PR fixes. Also memoize the resolved binary path.
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.
Fixes #256
Problem
Running
npx @counterscale/cli@latest installfails with:Root cause
The CLI spawned bare
npx wranglerfor every wrangler invocation (whoami,secret list,secret put,deploy).npxresolves wrangler from the user's environment — the npx cache entry keyed by the barewranglerspec (which is never auto-upgraded once cached),PATH, or a parentnode_modules— not the wrangler bundled with@counterscale/cli.When that resolution lands on wrangler < 3.78.10, it misinterprets the modern
assets: { directory }config inpackages/server/wrangler.jsonas legacy Workers Sites config and throws exactly this error (documented in Cloudflare's troubleshooting docs).Verified by running wrangler 3.60.0 against a CLI-staged config (reproduces the exact error), while the wrangler bundled with the CLI (4.x) parses the same config fine.
Fix
getBundledWranglerBinPath()which resolvesbin/wrangler.jsinside the CLI's own pinnedwrangler@^4.23.0dependency (viacreateRequire(...).resolve("wrangler/package.json"), which wrangler's exports map allows)node <bundled-bin>viawranglerArgv(), falling back to the oldnpx wranglerbehavior only if resolution failsconsole.warnexplains which wrangler is being used if the bundled binary can't be resolved; the resolved path is memoizednode <bin>implicitly raises the runtime floor —@counterscale/clialready requires Node >= 20 (engines field), so this is a non-issue in practiceTesting
cloudflare.test.tscovering bundled-binary resolution, memoization, the argv used bywhoami/secret list, the npx fallback, and the resolution-failure warnings@counterscale/cli: 109/109 tests pass, typecheck cleanFollow-up
echointowrangler secret put; special characters (newlines,$, backticks) can be mangled. Worth switching to stdin piping without a shell pipeline.