Skip to content

[Bug]: @astrojs/cloudflare prerender worker inherits queues.consumers, causing Miniflare ERR_MULTIPLE_CONSUMERS error #16199

Closed

Description

@adamchal

Astro Info

Astro                    v6.1.3
Vite                     v7.3.1
Node                     v25.8.2
System                   macOS (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/cloudflare (v13.1.7)
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When a project uses Cloudflare Queues (with queues.consumers in wrangler.json) and has a mix of prerendered and server-rendered pages, astro build fails with:

QueuesError [ERR_MULTIPLE_CONSUMERS]: Multiple consumers defined for queue "my-queue": "prerender" and "mre-prerender-queue"

The @astrojs/cloudflare adapter's prerenderWorker.config callback spreads the entire entryWorkerConfig into the prerender worker config:

// node_modules/@astrojs/cloudflare/dist/index.js, line 108
config(_, { entryWorkerConfig }) {
  return {
    ...entryWorkerConfig,   // <-- includes queues.consumers
    name: "prerender",
  };
},

This copies queues.consumers into the prerender worker. Miniflare then sees two workers (the entry worker and the prerender worker) both consuming the same queue and rejects the configuration.

What's the expected result?

The build should succeed. The prerender worker only needs to render static HTML — it should not inherit queue consumer bindings from the entry worker.


Potential fix

The prerenderWorker.config callback should strip queues.consumers (and potentially other non-applicable bindings) from the prerender worker config:

config(_, { entryWorkerConfig }) {
  const { queues, ...rest } = entryWorkerConfig;
  return {
    ...rest,
    name: "prerender",
    // Preserve producers but strip consumers so Miniflare doesn't
    // reject the config for having two workers consuming the same queue.
    ...(queues?.producers?.length && {
      queues: { producers: queues.producers },
    }),
  };
},

Link to Minimal Reproducible Example

https://github.com/adamchal/cloudflare-prerender-queue

Participation

  • I am willing to submit a pull request for this issue.

Activity

  1. added
    triage: needs triage
    on Apr 2, 2026
  2. astrobot-houston commented on Apr 2, 2026

    @astrobot-houston
    Contributor

    I was able to reproduce this issue. The @astrojs/cloudflare adapter's prerenderWorker.config callback spreads the entire entryWorkerConfig (including queues.consumers) into the prerender worker config. When Miniflare sees two workers (the entry worker and the prerender worker) both registered as consumers of the same queue, it rejects the configuration with ERR_MULTIPLE_CONSUMERS. The prerender worker only renders static HTML and has no need for queue consumer registrations.

    I was able to fix this issue. The fix destructures queues from entryWorkerConfig in the prerender worker config callback, dropping queues.consumers while preserving queues.producers (which are just bindings, not consumer registrations). This prevents Miniflare from seeing duplicate queue consumers. View Suggested Fix

    P3: minor bug. This affects users who use Cloudflare Queues with queues.consumers in their wrangler.json and have a hybrid site (mix of prerendered and server-rendered pages) using the default workerd prerender environment. This is a relatively specific combination of features, but it completely blocks builds for affected users with no workaround other than removing queue consumers from the config or switching to prerenderEnvironment: 'node'.

    Full Triage Report

    Triage Report: Issue #16199

    Original Issue

    Title: @astrojs/cloudflare prerender worker inherits queues.consumers, causing Miniflare ERR_MULTIPLE_CONSUMERS error

    Reporter: adamchal

    Description: When a project uses Cloudflare Queues (with queues.consumers in wrangler.json) and has a mix of prerendered and server-rendered pages, astro build fails with:

    QueuesError [ERR_MULTIPLE_CONSUMERS]: Multiple consumers defined for queue "my-queue": "prerender" and "mre-prerender-queue"
    

    Environment:

    • Astro v6.1.3
    • @astrojs/cloudflare v13.1.7
    • Node v25.8.2
    • macOS (x64)

    Reproduction

    Cloned MRE from https://github.com/adamchal/cloudflare-prerender-queue. The project has:

    • wrangler.json with queues.consumers and queues.producers for queue my-queue
    • A prerendered page (index.astro) and a server-rendered endpoint (api.ts with prerender = false)

    Steps:

    1. Set up a Cloudflare project with both prerendered and server-rendered pages
    2. Add queues.consumers to wrangler.json
    3. Run astro build

    Result: Build fails with Multiple consumers defined for queue "my-queue": "prerender" and "mre-prerender-queue"

    Root Cause

    File: packages/integrations/cloudflare/src/index.ts, lines 181-193

    The prerenderWorker.config callback spreads ...entryWorkerConfig directly into the prerender worker config, which includes queues.consumers. Miniflare then sees two workers both consuming the same queue and rejects the configuration. The prerender worker only renders static HTML and has no need for queue consumer registrations. This scenario was not considered when the prerender worker feature was introduced in PR #15711.

    Fix

    The prerenderWorker.config callback now destructures queues from entryWorkerConfig and only preserves queue producer bindings (dropping consumers):

     config(_, { entryWorkerConfig }) {
    +  const { queues, ...rest } = entryWorkerConfig;
       return {
    -    ...entryWorkerConfig,
    +    ...rest,
         name: 'prerender',
    +    ...(queues?.producers?.length && {
    +      queues: { producers: queues.producers },
    +    }),
       };
     },

    Verification: Before fix, ERR_MULTIPLE_CONSUMERS error occurs. After fix, the error is resolved. All 17 existing wrangler tests pass.

    This report was made by an LLM. Mistakes happen, check important info.

  3. added
    - P3: minor bug
    pkg: cloudflare
    and removed
    triage: needs triage
    on Apr 2, 2026
  4. matthewp commented on Apr 3, 2026

    @matthewp
    Contributor

    @adamchal could you submit a PR for this?

  5. corevibe555 commented on Apr 3, 2026

    @corevibe555

    @matthewp @adamchal If it's OK, I would love to contribute for this creating PR.
    Would you assign me please?
    Thank you!

  6. adamchal commented on Apr 3, 2026

    @adamchal
    MemberAuthor

    @corevibe555 yes, please. I think the identified Fix should suffice:

     config(_, { entryWorkerConfig }) {
    +  const { queues, ...rest } = entryWorkerConfig;
       return {
    -    ...entryWorkerConfig,
    +    ...rest,
         name: 'prerender',
    +    ...(queues?.producers?.length && {
    +      queues: { producers: queues.producers },
    +    }),
       };
     },

    I would also ask for an additional test fixture to be included (or maybe modified if appropriate) that covers this MRE scenario of a static build with a dynamic SSR endpoint that uses queues.

  7. added a commit that references this issue on Apr 7, 2026
    756e7be
  8. added a commit that references this issue on Apr 21, 2026
    ee079d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugpkg: cloudflare

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions