Skip to content

[autoconfig] Bump Next.js minimum versions & provide an automatic upgrade path - #14892

Open
ajhawkings wants to merge 2 commits into
cloudflare:mainfrom
ajhawkings:ahawkings/next-autoconfig-upgrade
Open

[autoconfig] Bump Next.js minimum versions & provide an automatic upgrade path#14892
ajhawkings wants to merge 2 commits into
cloudflare:mainfrom
ajhawkings:ahawkings/next-autoconfig-upgrade

Conversation

@ajhawkings

@ajhawkings ajhawkings commented Jul 28, 2026

Copy link
Copy Markdown
Member

Hi team, it's Angus here

Since opennextjs/opennextjs-cloudflare#1313, OpenNext requires minimum next versions ">=15.5.21 <16 || >=16.2.11". This PR bumps the minimum version in autoconfig to be 15.5.21

To make migrating simpler, this PR adds logic to automatically upgrade old (& vulnerable) Next 15 and 16 versions to the earliest compatible version within the same major release. Previously, @opennextjs/cloudflare migrate --force-install was run. This prints a bunch of peer dependency errors to the terminal during install but still succeeds, and lets users deploy the old version. This PR instead adds upgrading to autoconfig - which now confirms with the user that it will upgrade to the supported version:
image

  • 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: just changes autoconfig behaviour, actual minimum version changed elsewhere

A picture of a cute animal (not mandatory, but encouraged)

image
Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 72665dc

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

This PR includes changesets to release 4 packages
Name Type
@cloudflare/autoconfig Minor
wrangler Minor
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@ajhawkings
ajhawkings marked this pull request as draft July 28, 2026 10:35
@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 28, 2026
@workers-devprod
workers-devprod requested review from a team and emily-shen and removed request for a team July 28, 2026 10:36
@workers-devprod

workers-devprod commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/autoconfig-bump-next-and-auto-upgrade.md: [@cloudflare/wrangler]
  • packages/autoconfig/package.json: [@cloudflare/wrangler]
  • packages/autoconfig/src/frameworks/all-frameworks.ts: [@cloudflare/wrangler]
  • packages/autoconfig/src/frameworks/framework-class.ts: [@cloudflare/wrangler]
  • packages/autoconfig/src/frameworks/index.ts: [@cloudflare/wrangler]
  • packages/autoconfig/src/frameworks/next.ts: [@cloudflare/wrangler]
  • packages/autoconfig/src/run.ts: [@cloudflare/wrangler]
  • packages/autoconfig/src/types.ts: [@cloudflare/wrangler]
  • packages/autoconfig/tests/frameworks/next.test.ts: [@cloudflare/wrangler]
  • packages/autoconfig/tests/frameworks/validate-framework-version.test.ts: [@cloudflare/wrangler]
  • packages/autoconfig/tests/run-upgrade.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/autoconfig/run.test.ts: [@cloudflare/wrangler]
  • pnpm-lock.yaml: [@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: No Issues Found

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

View in Devin Review to see 1 additional finding.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/autoconfig@14892

@cloudflare/build-output-utils

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/build-output-utils@14892

@cloudflare/config

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/config@14892

create-cloudflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/create-cloudflare@14892

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/deploy-helpers@14892

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/kv-asset-handler@14892

miniflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/miniflare@14892

@cloudflare/pages-functions

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-functions@14892

@cloudflare/pages-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-shared@14892

@cloudflare/unenv-preset

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/unenv-preset@14892

@cloudflare/vite-plugin

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vite-plugin@14892

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

npm i https://pkg.pr.new/cloudflare/workers-sdk/wrangler@14892

commit: 72665dc

@ajhawkings
ajhawkings force-pushed the ahawkings/next-autoconfig-upgrade branch from c095cff to 6fe4d5a Compare July 28, 2026 10:59
@ajhawkings
ajhawkings marked this pull request as ready for review July 28, 2026 13:29
@ajhawkings
ajhawkings force-pushed the ahawkings/next-autoconfig-upgrade branch from 6fe4d5a to 082b0a9 Compare July 28, 2026 14:52
Comment thread packages/autoconfig/src/frameworks/framework-class.ts Outdated
@@ -1,5 +1,6 @@
import assert from "node:assert";
import semiver from "semiver";
import semverSatisfies from "semver/functions/satisfies.js";

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.

can we not use semiver which is already installed?

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.

can do but it can't handle satisfies strings, only individual comparisons, so configuration would have to be a bit more wordy

does something like this work, and then semiver can be used:

    upgradeRequired: [
       { from: "15.1.0", to: "15.5.20", upgradeTo: "15.5.21" },
       { from: "16.0.0", to: "16.2.10", upgradeTo: "16.2.11" }
    ]

"@opennextjs/cloudflare",
"migrate",
// Note: we force-install so that even if an incompatible version of
// Next.js is used this installation still succeeds, moving users

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.

given the intent of this comment, should we fallback to force installing if someone is on a version of nextjs that we can't upgrade for them? this way they'll still have all the cloudflare config files etc. and we can tell them to sort out the framework version later

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.

For next 14 and 15.0.x?

can do, but I think that will require a bit of a refactor as currently anything below minimumVersion is blocked from proceeding. and I think it might require a change in opennext as well to more clearly warn people that they shouldn't deploy that old version. at the moment because of force-install, wrangler deploy autoconfigures the old unsupported version and then happily deploys it 😅

I feel like an alternative might be a custom error message when next 14 is detected which tells people how to use the next codemod to upgrade. then, they upgrade first and wrangler deploy all in one go. don't think this is too difficult to add - just involves overriding the global error in frameworks/next.ts 🙂

Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com>

@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 1 new potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +18 to +22
isWorkspaceRoot,
startText: `Updating Next.js to ${upgradeTo}`,
doneText: `${brandColor("updated")} ${dim(`Next.js to ${upgradeTo}`)}`,
});
}

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.

🟡 Framework version update can be applied to the wrong directory when the project is not the current directory

The Next.js update is installed in whatever directory the command happens to be running in (installPackages at packages/autoconfig/src/frameworks/next.ts:18) instead of the detected project directory, so when the two differ the project is left unchanged and setup aborts with a "update it manually" error.
Impact: Users who run setup from outside their project folder get a failed setup and an unrelated directory's dependencies modified.

Mechanism: installPackages resolves the install target from process.cwd(), while the rest of autoconfig uses autoConfigDetails.projectPath

installPackages (packages/cli/packages.ts:27-124) never passes a cwd to runCommand for the non-empty package list branch, and its npm package.json fix-up reads path.join(process.cwd(), "package.json"). Every other autoconfig step keys off autoConfigDetails.projectPath (e.g. version detection at packages/autoconfig/src/run.ts:114-120, package.json rewrite at packages/autoconfig/src/run.ts:229-252), and projectPath is only defaulted to process.cwd() (packages/autoconfig/src/details/index.ts:90) — callers may pass a different path. When they differ, the install lands elsewhere, the post-upgrade re-validation at packages/autoconfig/src/run.ts:192-208 still reads the old version, and setup throws "…but the version installed in the project is still …". Passing the project path through to the install (or forwarding it as cwd) would make the upgrade consistent with the rest of the flow.

Prompt for agents
In packages/autoconfig/src/frameworks/next.ts, upgradeFrameworkVersion calls installPackages, which (see packages/cli/packages.ts) runs the package manager in process.cwd() and rewrites process.cwd()/package.json for npm. All other autoconfig operations operate on autoConfigDetails.projectPath, which defaults to process.cwd() but can be passed explicitly by callers (packages/autoconfig/src/details/index.ts). If projectPath differs from the process cwd, the Next.js upgrade is applied to the wrong directory, and the post-upgrade re-validation in packages/autoconfig/src/run.ts then throws an 'update it manually' error. Consider threading projectPath into FrameworkVersionUpgradeOptions and having the install helper accept/forward a cwd so the upgrade targets the same directory as the rest of the flow.
Open in 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.

Think this is how it's done in all the other framework files – they use don't use projectPath? Might be a separate issue

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.

3 participants