Skip to content

Conversation

@MattieTK
Copy link
Member

@MattieTK MattieTK commented Feb 5, 2026

When users run wrangler setup using a package manager that doesn't match their project (e.g. npx wrangler setup in a pnpm workspace), the command fails because npm cannot handle the workspace: protocol used by pnpm and yarn workspaces.

The existing getPackageManager() function relies on npm_config_user_agent to detect which package manager invoked the command. When this doesn't match the project's actual package manager, autoconfig generates incorrect commands and may fail during dependency installation with errors like:

  • npm error code EUNSUPPORTEDPROTOCOL for workspace: protocol
  • npm error Cannot read properties of null (reading 'matches')

This change detects the project's package manager from lockfiles and packageManager field rather than from how wrangler was invoked.

Why only in autoconfig?

This fix is scoped to wrangler setup rather than changing getPackageManager() globally because:

  1. @netlify/build-info is already a dependency here for framework detection, and its Project class provides robust package manager detection as a side effect of getBuildSettings()
  2. Adding this dependency elsewhere in wrangler would increase bundle size for commands that don't need it
  3. The autoconfig flow is the primary place where the detected package manager materially affects behaviour (generating build commands, install scripts, etc.)

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: Bug fix for existing behaviour, no API change

Open with Devin

@MattieTK MattieTK requested a review from a team as a code owner February 5, 2026 21:37
@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

🦋 Changeset detected

Latest commit: f34f3d1

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude
Copy link
Contributor

claude bot commented Feb 5, 2026

Claude finished @MattieTK's task —— View job


Changeset Review

  • Read changeset guidelines
  • Review .changeset/autoconfig-pm-detection.md
  • Validate changeset quality
  • Check attached image

⚠️ Issues found

Typo in title

Line 5 contains a typo: "wranger" should be "wrangler"

-fix: use project's package manager in wranger autoconfig
+fix: use project's package manager in wrangler autoconfig

Other validation checks:

  • Version Type: patch is appropriate for a bug fix
  • Changelog Quality: Good description with clear explanation of the problem and solution
  • Markdown Headers: No h1/h2/h3 headers used
  • Analytics: No analytics changes
  • Experimental features: Not applicable

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 5, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12437

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12437

miniflare

npm i https://pkg.pr.new/miniflare@12437

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12437

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12437

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12437

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12437

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12437

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12437

wrangler

npm i https://pkg.pr.new/wrangler@12437

commit: f34f3d1

@MattieTK MattieTK force-pushed the mattietk/autoconfig-pm-detection branch from 30855bc to b3438c0 Compare February 5, 2026 21:46
Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, thanks @MattieTK 🙂

I just left a few small comments all non blocking

It seems like the tests however need some fixing 🥲

@MattieTK MattieTK force-pushed the mattietk/autoconfig-pm-detection branch from b3438c0 to 35ebd5e Compare February 6, 2026 00:53
Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assuming that the CI failures are addressed of course

Thanks @MattieTK! 🫶

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Feb 6, 2026
wrangler setup now detects the project's package manager from lockfiles
and packageManager field instead of defaulting to npm. This fixes failures
in pnpm/yarn workspace projects where npm cannot handle workspace: protocol.

Leverages existing @netlify/build-info detection from framework analysis.
The AutoConfigDetailsBase type now requires packageManager, but several
test files were constructing AutoConfigDetails without it. Also updated
vi.mock calls to preserve NpmPackageManager export and fixed a
consistent-type-imports lint violation in setup.test.ts.
@MattieTK MattieTK force-pushed the mattietk/autoconfig-pm-detection branch from 08dcf96 to f34f3d1 Compare February 10, 2026 17:16
@MattieTK MattieTK merged commit ad817dd into main Feb 11, 2026
35 checks passed
@MattieTK MattieTK deleted the mattietk/autoconfig-pm-detection branch February 11, 2026 14:27
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants