[autoconfig] Bump Next.js minimum versions & provide an automatic upgrade path - #14892
[autoconfig] Bump Next.js minimum versions & provide an automatic upgrade path#14892ajhawkings wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 72665dc The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
c095cff to
6fe4d5a
Compare
6fe4d5a to
082b0a9
Compare
| @@ -1,5 +1,6 @@ | |||
| import assert from "node:assert"; | |||
| import semiver from "semiver"; | |||
| import semverSatisfies from "semver/functions/satisfies.js"; | |||
There was a problem hiding this comment.
can we not use semiver which is already installed?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
| isWorkspaceRoot, | ||
| startText: `Updating Next.js to ${upgradeTo}`, | ||
| doneText: `${brandColor("updated")} ${dim(`Next.js to ${upgradeTo}`)}`, | ||
| }); | ||
| } |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Think this is how it's done in all the other framework files – they use don't use projectPath? Might be a separate issue
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 be15.5.21To 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-installwas 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:A picture of a cute animal (not mandatory, but encouraged)