Skip to content

[wrangler] fix: resolve secondary worker types when environment overrides worker name#13061

Merged
petebacondarwin merged 2 commits intocloudflare:mainfrom
petebacondarwin:fix/type-generation-multi-worker-env
Mar 26, 2026
Merged

[wrangler] fix: resolve secondary worker types when environment overrides worker name#13061
petebacondarwin merged 2 commits intocloudflare:mainfrom
petebacondarwin:fix/type-generation-multi-worker-env

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin commented Mar 25, 2026

Fixes #12971.

When running wrangler types with multiple -c config flags, secondary workers that have named environments which override the worker name (e.g. name: "do-worker" with env.staging.name: "do-worker-staging") were not being resolved correctly. Any service binding or Durable Object binding in the primary worker that referenced the environment-qualified name (e.g. do-worker-staging) would fall back to an unresolved comment type like:

DurableObjectNamespace /* MyDurableObject from do-worker-staging */
// instead of:
DurableObjectNamespace<import("../secondary/index").MyDurableObject>

This produced ugly union types in the generated Env interface since both the top-level and env-specific bindings could be for different resolved/unresolved types.

Root cause: The secondaryEntries map (which maps worker names to their entry file paths) was only populated with the top-level worker name from each secondary config. When a binding referenced an env-qualified name like do-worker-staging, the lookup missed and fell back to the comment-style unresolved type.

Fix: After registering the top-level name for a secondary config, also read the raw config to iterate over all named environments, load the config for each env, and register the env-specific effective name pointing to the same source entry file.


  • 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: this is a bug fix with no API surface changes

Open with Devin

@petebacondarwin petebacondarwin requested a review from a team as a code owner March 25, 2026 21:40
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 25, 2026

🦋 Changeset detected

Latest commit: 919c6b3

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

@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 25, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
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 2 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 25, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 919c6b3

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 26, 2026
@petebacondarwin petebacondarwin merged commit 535582d into cloudflare:main Mar 26, 2026
47 of 48 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 26, 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.

Type generation is broken in a multi-worker setup with multiple environments

3 participants