Skip to content

Conversation

timReynolds
Copy link

This PR updates the opennextjs-cloudflare CLI to correctly pass through multiple configuration files to Wrangler, allowing multiple workers to be bound to a single dev session. This is helpful when using Durable Objects, which aren't bound to the worker when using Miniflare locally, as per the CLI warning.

CleanShot 2025-09-21 at 13 22 23@2x

This reduces the need to run two dev sessions locally and ensures you can use RPC with DO locally, as per the supported binding docs.

Developers can enable this by updating preview to:

pnpm run build && opennextjs-cloudflare preview -c wrangler.jsonc -c src/agents/wrangler.jsonc

You can do this today; however, you'll encounter an error when an array is passed through to unstable_readConfig unexpectedly, as yargs will return an array of strings for config without error, misaligned with its typing.

As the CLI has to read the config file used for OpenNext to support some features, I've made the choice to assume the first config passed is the one used to define the worker for Next.js. This might not be the best choice but felt more aligned with Wrangler than adding additional config flags.

Given this usage is probably an edge case and most users don't pass config, it seemed like a reasonable trade-off.

One item that could use more work but would require more code changes is ensuring the info message I added is below the header. I'm happy to make this change if people would consider merging this.

CleanShot 2025-09-21 at 14 03 24@2x

@Copilot Copilot AI review requested due to automatic review settings September 21, 2025 13:09
Copy link

changeset-bot bot commented Sep 21, 2025

🦋 Changeset detected

Latest commit: f7187b9

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

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Minor

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

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for passing multiple Wrangler configuration files to the opennextjs-cloudflare CLI, enabling developers to bind multiple workers to a single dev session for local development with Durable Objects and RPC communication.

  • Updates the CLI to accept multiple --config flags as an array of configuration paths
  • Introduces nextjsWranglerConfigPath to maintain compatibility with existing OpenNext functionality
  • Adds informational logging when multiple configs are detected

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/cloudflare/src/cli/commands/utils.ts Core implementation adding array support for config option and new type definitions
packages/cloudflare/src/cli/commands/upload.ts Updated to use nextjsWranglerConfigPath for OpenNext-specific operations
packages/cloudflare/src/cli/commands/preview.ts Updated to use nextjsWranglerConfigPath for OpenNext-specific operations
packages/cloudflare/src/cli/commands/populate-cache.ts Updated to use nextjsWranglerConfigPath for OpenNext-specific operations
packages/cloudflare/src/cli/commands/deploy.ts Updated to use nextjsWranglerConfigPath for OpenNext-specific operations
.changeset/weak-crews-tickle.md Changelog entry documenting the new multiple config support feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

...args,
wranglerConfigPath: args.config ?? args.configPath,
wranglerConfigPath,
nextjsWranglerConfigPath: wranglerConfigPath?.[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly this will only work when the next app config is first which is not ideal.

Can't you run opennextjs-cloudflare ... (for the next app) and wrangler dev ... for other workers?

Copy link
Author

Choose a reason for hiding this comment

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

I agree this isn't ideal but I couldn't think of another solution.

You can run them in separate dev sessions but you'll hit them limitation outline in the documentation;

If you are not using RPC with your Durable Object, you can run a separate Wrangler dev session alongside your framework development server.
Otherwise, you can build your application and run both Workers in the same Wrangler dev session.

I found this when trying to port the agents starter to opennext-cloudflare which is working when I link this change.

I'm trying to run them locally in separate dev sessions now but its having an issue upgrading to web-sockets I've not debugged yet.

I'm open to other ways of solving this or I can just open an issue so it can be fixed upstream in wrangler somehow

@vicb
Copy link
Contributor

vicb commented Sep 23, 2025

Sounds like inter process communication is coming soon.
I'll update the issue when I have more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants