[@next/codemod] Does not work if repository has specified `devEngines.packageManager` as pnpm
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/oBusk/next-codemod-error
To Reproduce
- In a next.js repository, configure the
devEngines.packageManagerfield topnpm(or checkout the repo) - 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with packages/next-codemod/bin/upgrade.ts around line 99 and reproduce the issue with pnpx @next/codemod@canary upgrade latest in the linked repository. Trace how the silent npm view failure is handled when devEngines.packageManager is pnpm. Done means the upgrade command works with that setting or reports a clear, actionable error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js, node.js
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100