nextjs - ✅(Solved) Fix [@next/codemod] Does not work if repository has specified `devEngines.packageManager` as pnpm [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85587Fetched 2026-04-08 02:14:57
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Timeline (top)
commented ×1cross-referenced ×1issue_type_added ×1

Error Message

https://github.com/oBusk/next-codemod-error Right now you will get a (confusing) error: Secondary: Give a better error, like that npm didn't work or something. I've tracked it down to the code used to check what next versions are available. It tries to execute npm view, npm refuses to run because repo has devEngine.packageManager set to pnpm. Because command is run --silent, no error is printed, and it executes in a try/catch, but without any error handling.

Root Cause

I've tracked it down to the code used to check what next versions are available. It tries to execute npm view, npm refuses to run because repo has devEngine.packageManager set to pnpm. Because command is run --silent, no error is printed, and it executes in a try/catch, but without any error handling.

Fix Action

Fix / Workaround

The workaround if anyone else is running in to this issue is to drop the devEngines.packageManager field for now.

PR fix notes

PR #85591: [@next/codemod] Fix upgrade failing when devEngines.packageManager is set to pnpm

Description (problem / solution / changelog)

What?

  • Print clearer errors if npm view fails, avoiding the user trying to fix their input that was fine all along.

  • Stop fetching of next versions from failing because user has specified devEngines.packageManager in their package.json

  • Print out more error information when npm view fails

  • Run npm view with -g flag to make it ignore any devEngines.packageManager rules

Why?

As a user, if you run pnpx @next/codemod@canary upgrade latest inside a repo with the devEngines.packageManager field set to { "name": "pnpm" } (or something else non-npm), you will recieve an error

Invalid revision provided: "latest". Please provide a valid Next.js version or dist-tag (e.g. "latest", "canary", "beta", "rc", or "15.0.0")

Which is a very confusing message of course.

The reason for this is that npm view fails to execute because since npm v10.9.0, npm will fail any command when devEngines.packageManager is set to something else than npm. And the code just checks if any value was returned, and if it was not, assumes the user passed a bad revision input.

How?

As mentioned in the original issue, npm does not have any env, flag or command to skip the devEngines.packageManager check, see https://github.com/npm/rfcs/issues/830 for discussion.

What npm does have is the general --force flag which skips this, and other checks. Obviously skipping other checks is unwanted, but for npm view it's probably, arguably fine, considering what the command does. And I was about to open a PR using npm --force --silent view, but then I had a thought and tried it with npm -g and realized that this works! The operation we're performing is looking up in the registry what versions are available, and not anything specific to the local package, so -g for global seems like a good option.

Questions

  • I was not entirely sure how to parse the errors returned by `npm view´, and right now have opted to just print the errors as is to console, followed by throwing a friendlier message. If we want to parse the error in more detail, I could try it.

    {
      "error": {
        "code": "E404",
        "summary": "No match found for version 17",
        "detail": "The requested resource 'next@17' could not be found or you do not have permission to access it.\n\nNote that you can also install from a\ntarball, folder, http url, or git url."
      }
    }
    
    Failed to fetch Next.js versions using npm view.
  • I wonder if the code checking if version returned by npm view is now superflous since any fail, such as the spec not hitting would be printed and the checking of the returned value will never run.

  • I'm not sure if the --global command has any unwanted effects on npm view. One thing I'm considering is if a user has configured some other registry in a local .npmrc, then I imagine that npm -g view might ignore that file? Is that a case that should be catered?

Fixes vercel/next.js#85587

Changed files

  • packages/next-codemod/bin/upgrade.ts (modified, +13/-3)

Code Example

$ pnpx @next/codemod@canary upgrade latest
Invalid revision provided: "latest". Please provide a valid Next.js version or dist-tag (e.g. "latest", "canary", "beta", "rc", or "15.0.0").
Check available versions at https://www.npmjs.com/package/next?activeTab=versions.

---

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32691
  Available CPU cores: 24
Binaries:
  Node: 20.19.5
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.20.0
Relevant Packages:
  next: 15.5.6
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/oBusk/next-codemod-error

To Reproduce

  1. In a next.js repository, configure the devEngines.packageManager field to pnpm (or checkout the repo)
  2. Inside that repo, try to execute the upgrade codemod with pnpx @next/codemod@canary upgrade latest

Current vs. Expected behavior

Right now you will get a (confusing) error:

$ pnpx @next/codemod@canary upgrade latest
Invalid revision provided: "latest". Please provide a valid Next.js version or dist-tag (e.g. "latest", "canary", "beta", "rc", or "15.0.0").
Check available versions at https://www.npmjs.com/package/next?activeTab=versions.

I would expect it to

Primarily: continue working as expected Secondary: Give a better error, like that npm didn't work or something.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32691
  Available CPU cores: 24
Binaries:
  Node: 20.19.5
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.20.0
Relevant Packages:
  next: 15.5.6
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local), next dev (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

Same behaviour regardless of bash vs. powershell on windows, or bash on linux. Same behaviour with @next/codemod@canary, @next/codemod@16 and @next/codemod@15.

I've tracked it down to the code used to check what next versions are available. It tries to execute npm view, npm refuses to run because repo has devEngine.packageManager set to pnpm. Because command is run --silent, no error is printed, and it executes in a try/catch, but without any error handling.

The workaround if anyone else is running in to this issue is to drop the devEngines.packageManager field for now.

As for solving the problem, I think according to https://github.com/npm/rfcs/issues/830 that there's currently no way to execute npm without --force, that overrides other things too. But might be easiest way to fix this until there is some other way to execute npm commands while ignoring devEngines. Otherwise, don't know if adapting code to use configured packagemanager for all operations, including pure lookups, or if npm view is handled by one of the npm subpackages, or if just writing some code to check npmjs registry directly is best solution.

extent analysis

TL;DR

The most likely fix is to modify the upgrade.ts file to handle the devEngines.packageManager field or use the configured package manager for npm operations.

Guidance

  • The issue is caused by npm view being executed with --silent flag and no error handling, resulting in a confusing error message when devEngines.packageManager is set to pnpm.
  • To verify the issue, try removing the devEngines.packageManager field from the package.json file and re-run the pnpx @next/codemod@canary upgrade latest command.
  • A possible workaround is to drop the devEngines.packageManager field for now, as mentioned in the issue description.
  • Another potential solution is to adapt the code to use the configured package manager for all operations, including pure lookups, or to write code to check the npmjs registry directly.

Example

No code snippet is provided as it requires modifying the upgrade.ts file, which is not explicitly stated in the issue.

Notes

The issue is specific to the next-codemod package and its interaction with npm and pnpm. The solution may require changes to the upgrade.ts file or the package.json file.

Recommendation

Apply workaround: Drop the devEngines.packageManager field for now, as it is the simplest solution until a more permanent fix is implemented.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - ✅(Solved) Fix [@next/codemod] Does not work if repository has specified `devEngines.packageManager` as pnpm [1 pull requests, 1 comments, 2 participants]