AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

`Next Info` Reports Incorrect Version For Canary Releases

The `next info` command incorrectly displays the latest stable version instead of the actual installed canary version, misleading users about their Next.js version.

mediumConfidence 85%Next.jsAffected V16.3.6

Origin Analysis

The version detection logic in `next info` prioritizes the latest stable version retrieved from the npm registry over the locally installed version from `package.json`, causing canary versions to be replaced with the latest stable version.
1. Install a Next.js canary version (e.g., 16.4.0-canary.43).\n2. Run `next info`.\n3. Observe that the reported version is the latest stable version (e.g., 16.3.6) instead of the installed canary version.

Fixing Code Block

// packages/next/src/cli/next-info.ts import { readFileSync } from 'fs' import { join } from 'path' // 修复版本获取逻辑:从本地 node_modules 读取实际安装版本 function getInstalledVersion(): string { try { const packageJsonPath = join(process.cwd(), 'node_modules', 'next', 'package.json') const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) return packageJson.version } catch { // 回退到环境变量或未知 return process.env.__NEXT_VERSION || 'unknown' } } // 在生成 info 输出时,将 currentVersion 设置为 getInstalledVersion() 的结果 // 替换原来的逻辑:const latestVersion = await fetchLatestVersion('next') // const currentVersion = process.env.__NEXT_VERSION || latestVersion // 改为: const currentVersion = getInstalledVersion() // 后续代码使用 currentVersion 输出
The fix reads the version directly from the locally installed `next` package's `package.json`, ensuring that the actual installed version (including canary) is reported. It falls back to `process.env.__NEXT_VERSION` or 'unknown' only if the file cannot be read.

Edge Case Audit

If the project uses a non-standard installation path (e.g., monorepo, pnpm, Yarn PnP, or global install), `process.cwd()/node_modules/next/package.json` may not exist, causing the fallback to `unknown`. To mitigate, use module resolution (e.g., `require.resolve('next/package.json')`) instead of assuming a fixed path. Rollback: If this fix causes version reading failures, revert to the previous logic that used `process.env.__NEXT_VERSION` or the registry.

Ecosystem Topology