Skip to content

fix: use detected package manager in install error/hint messages#187

Merged
southpolesteve merged 2 commits intocloudflare:mainfrom
justinfinnn:fix/use-detected-package-manager-in-error-messages
Mar 3, 2026
Merged

fix: use detected package manager in install error/hint messages#187
southpolesteve merged 2 commits intocloudflare:mainfrom
justinfinnn:fix/use-detected-package-manager-in-error-messages

Conversation

@justinfinnn
Copy link
Contributor

Problem

Error messages and install hints in index.ts, check.ts, and cli.ts were hardcoded to use npm install, even when the project uses Yarn, pnpm, or Bun.

For example, on a Yarn workspace project:

vinext: App Router detected but @vitejs/plugin-rsc is not installed.
Run: npm install -D @vitejs/plugin-rsc   ← wrong for Yarn users

Solution

Use the existing detectPackageManager() and detectPackageManagerName() utilities from utils/project.ts — which already correctly detect the package manager from lockfiles and are already used in deploy.ts.

After this fix (on a Yarn project):

vinext: App Router detected but @vitejs/plugin-rsc is not installed.
Run: yarn add -D @vitejs/plugin-rsc   ← correct!

Changes

  • src/index.ts — 3 error/warning messages: @vitejs/plugin-rsc not installed (×2), @mdx-js/rollup not installed
  • src/check.ts — install hint shown to users during vinext check
  • src/cli.ts — eslint/oxlint install suggestions

Related

Closes #186
Relates to #109

@southpolesteve
Copy link
Collaborator

/bigbonk review

ask-bonk[bot]
ask-bonk bot previously requested changes Mar 3, 2026
Copy link
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Good idea — the hardcoded npm install messages are a real UX papercut for non-npm users. The approach of reusing the existing detectPackageManager() / detectPackageManagerName() utilities is correct.

One bug to fix in cli.ts before merging.

console.log(
" No linter found. Install eslint or oxlint:\n\n" +
" npm install -D eslint eslint-config-next\n" +
" " + detectPackageManagerName(process.cwd()) + " add -D eslint eslint-config-next\n" +
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: detectPackageManagerName() returns the bare name ("npm", "yarn", etc.), and you append " add -D". But npm's subcommand is install, not add. For npm users this would produce:

npm add -D eslint eslint-config-next

While npm add technically works (it's an undocumented alias for npm install), it's non-standard and inconsistent with how detectPackageManager() returns "npm install -D" for the other call sites.

Use detectPackageManager() instead (same as check.ts and index.ts), which already returns the correct install command with flags:

Suggested change
" " + detectPackageManagerName(process.cwd()) + " add -D eslint eslint-config-next\n" +
" " + detectPackageManager(process.cwd()) + " eslint eslint-config-next\n" +

" " + detectPackageManagerName(process.cwd()) + " add -D eslint eslint-config-next\n" +
" # or\n" +
" npm install -D oxlint\n",
" " + detectPackageManagerName(process.cwd()) + " add -D oxlint\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue — use detectPackageManager() for consistency:

Suggested change
" " + detectPackageManagerName(process.cwd()) + " add -D oxlint\n",
" " + detectPackageManager(process.cwd()) + " oxlint\n",

import { pathToFileURL } from "node:url";
import { createRequire } from "node:module";
import { execFileSync } from "node:child_process";
import { detectPackageManagerName } from "./utils/project.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

If you switch to detectPackageManager per the suggestions below, update this import accordingly:

Suggested change
import { detectPackageManagerName } from "./utils/project.js";
import { detectPackageManager } from "./utils/project.js";

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 3, 2026

Review submitted. Here's a summary:

Requested changes on PR #187

The PR correctly identifies that hardcoded npm install messages are wrong for Yarn/pnpm/Bun users, and the fix in check.ts and index.ts using detectPackageManager() is correct.

Bug in cli.ts: The PR uses detectPackageManagerName() (returns bare name like "npm") and manually appends " add -D". This produces npm add -D ... for npm users — while technically functional (undocumented alias), it's non-standard and inconsistent with the other two files which use detectPackageManager() (returns "npm install -D"). The fix is to use detectPackageManager() in cli.ts as well, matching the pattern in check.ts and index.ts.

github run

Homiebot and others added 2 commits March 3, 2026 11:05
Error messages and install hints in index.ts, check.ts, and cli.ts
were hardcoded to use `npm install`. This PR uses the existing
`detectPackageManager()` / `detectPackageManagerName()` utilities
(already used correctly in deploy.ts) so that Yarn, pnpm, and Bun
users see the right install command.

Before (on a Yarn project):
  Run: npm install -D @vitejs/plugin-rsc

After:
  Run: yarn add -D @vitejs/plugin-rsc

Fixes cloudflare#186
Replace detectPackageManagerName() + manual 'add -D' with
detectPackageManager() which already returns the correct install
command. This avoids producing 'npm add -D' (undocumented alias)
for npm users and stays consistent with check.ts and index.ts.
@southpolesteve southpolesteve force-pushed the fix/use-detected-package-manager-in-error-messages branch from 2bd76d3 to 84e4670 Compare March 3, 2026 17:06
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 3, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@187

commit: aeab27e

@southpolesteve southpolesteve enabled auto-merge (squash) March 3, 2026 17:10
@southpolesteve southpolesteve merged commit 8058c34 into cloudflare:main Mar 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vinext deploy silently runs npm install, downgrading dependencies in Yarn/pnpm workspaces

2 participants