Skip to content

[autoconfig] Configure Next.js 16 projects with vinext for cf - #16200

Draft
MattieTK wants to merge 1 commit into
mainfrom
autoconfig-vinext-for-cf
Draft

MattieTK wants to merge 1 commit into
mainfrom
autoconfig-vinext-for-cf

Conversation

@MattieTK

@MattieTK MattieTK commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Fixes N/A.

When targeting cf, autoconfig configures Next.js projects with @opennextjs/cloudflare migrate. OpenNext builds into .open-next/, while cf builds and deploys from the Build Output under .cloudflare/output/v0/. vinext builds Next.js apps with the Cloudflare Vite plugin and its init command already targets cf, so this uses it for the cf target instead.

  • For the cf target on Next.js 16 or later, NextJs.configure() runs vinext init --platform=cloudflare --cdn-cache=none --image-optimization=cloudflare-images --no-prerender. These flags match vinext's non-interactive defaults; without them vinext init prompts, and fails in agent environments. --no-prerender is passed because Cloudflare serves pre-rendered routes only with the Static Assets cache.
  • It returns workerConfig: null because vinext init writes cloudflare.config.ts, and returns a vite build build command.
  • vinext supports Next.js 16 only, so earlier versions (including 16 prereleases) continue to use OpenNext. The Wrangler target is unchanged.
  • The summary's configuration description now names the tool that will run.

Validation: the autoconfig suite passes, as do the package typecheck and scoped lint and format checks. I also ran the built package against a fresh create-next-app project (Next.js 16.4.0) with target: "cf" from an agent environment: vinext init completed without prompting, the generated cloudflare.config.ts was preserved, and vite build produced .cloudflare/output/v0/workers/default.

Merge order

This is one of three related changes:

  1. fix: analyse the project again after framework setup cf#260 (re-analyse the project after setup) can merge at any time. It has no visible effect with the current @cloudflare/autoconfig, but it must be in cf before step 4, otherwise the first cf dev after setup runs next dev rather than vite dev.
  2. feat(init): add --name to set the Cloudflare Worker name vinext#3863 (add --name to vinext init) merges and is released.
  3. [autoconfig] Configure Next.js 16 projects with vinext for cf #16200 (use vinext for Next.js 16 on the cf target) is updated to pass the Worker name chosen during setup to vinext init --name and to require the vinext release from step 2. It then merges and @cloudflare/autoconfig is released. (this PR)
  4. cf bumps @cloudflare/autoconfig to the release from step 3, after fix: analyse the project again after framework setup cf#260 has merged.

  • 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: The documented automatic configuration for Wrangler is unchanged; this only affects the cf target.

OpenNext builds into .open-next/ rather than the Build Output under
.cloudflare/output/v0/ that cf deploys. vinext builds with the Cloudflare
Vite plugin and writes cloudflare.config.ts itself, so use it for the cf
target on the Next.js versions it supports. Earlier Next.js versions and
the Wrangler target keep using OpenNext.
@changeset-bot

changeset-bot Bot commented Oct 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 72ccac1

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/autoconfig 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

@ask-bonk

ask-bonk Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

semiver(..., "16.0.0") >= 0 also matches Next.js 17 and later, so this will migrate those projects to vinext even though vinext supports only the 16.x API surface. Keep the existing OpenNext path for later majors as well.

		return (
			target === "cf" &&
			this.frameworkVersion.startsWith("16.") &&
			semiver(this.frameworkVersion, VINEXT_MINIMUM_NEXT_VERSION) >= 0
		);

@ask-bonk

ask-bonk Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Configures Next.js 16 cf projects with vinext instead of OpenNext.

  1. P1 packages/autoconfig/src/frameworks/next.ts:47 selects vinext for Next.js 17+, which vinext does not support. Posted a suggestion comment.

github run

@pkg-pr-new

pkg-pr-new Bot commented Oct 11, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@16200

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@16200

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@16200

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@16200

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@16200

create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@16200

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@16200

@cloudflare/pages-shared

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

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@16200

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@16200

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@16200

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 72ccac1

@MattieTK

Copy link
Copy Markdown
Member Author

heads up @james-elicx

@workers-devprod
workers-devprod requested review from a team and petebacondarwin and removed request for a team October 11, 2026 10:35
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/autoconfig-next-vinext-for-cf.md: [@cloudflare/wrangler]
  • packages/autoconfig/src/frameworks/next.ts: [@cloudflare/wrangler]
  • packages/autoconfig/tests/frameworks/next.test.ts: [@cloudflare/wrangler]

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment on lines +65 to +82
if (!dryRun) {
await runCommand(
[
...dlx,
"vinext",
"init",
// `vinext init` prompts for these choices and fails in agent environments
// when they are missing, so we pass the defaults it uses when non-interactive
"--platform=cloudflare",
"--cdn-cache=none",
"--image-optimization=cloudflare-images",
// Cloudflare only serves pre-rendered routes when using the Static Assets cache
"--no-prerender",
],
{
cwd: projectPath,
}
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Selected Worker name is ignored

When a user selects a different Worker name, vinext init receives no workerName. The generated configuration bypasses runAutoConfig, so deployment uses vinext's name instead.

Learn more

Autoconfig lets users choose a Worker name in confirmAutoConfigDetails. runAutoConfig normally writes it as the default Worker name, but workerConfig: null makes it preserve vinext's generated configuration instead. The command does not pass the chosen name to vinext.

Example: A project named storefront chooses storefront-production in the Worker-name prompt. Vinext receives no selected name, so deployment uses its generated name instead.

Recommended fix: Pass workerName to vinext if supported, or update the generated cloudflare.config.ts to use the selected name without discarding vinext's settings.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread packages/autoconfig/src/frameworks/next.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants