vercel/next.js · error · Error

Could not determine the installed Next.js version.

Error message

Could not determine the installed Next.js version.

What it means

prepareUpgrade resolves the app's own next/package.json via createRequire from the app directory and reads its version. If that version string is not valid semver, the CLI cannot compute upgrade targets or compare advisory ranges, so it throws rather than guessing.

Solutions

  1. Install a published next release: npm i next@latest (or a pinned stable version)
  2. Check the installed version: node -e "console.log(require('next/package.json').version)" and ensure it is valid semver
  3. If using a fork/local build, give it a valid semver version field
  4. Clear node_modules and reinstall to repair a corrupted install

Example fix

// before (package.json)
"next": "github:vercel/next.js#canary"
// after
"next": "^15.0.0"
Defensive patterns

Strategy: validation

Validate before calling

const semver = require('semver')
const v = require('next/package.json').version
if (!semver.valid(v)) console.error('Installed next version is not valid semver:', v)

Try / catch

try {
  await prepareUpgrade(dir, 'latest')
} catch (e) {
  if (e.message.includes('installed Next.js version')) {
    // reinstall a published next release
  }
}

Prevention

When it happens

Trigger: next is installed with a non-semver version field (git dependency, file: link to a source checkout, npm alias with altered metadata, corrupted node_modules).

Common situations: Installing next from a git URL or a patched tarball whose package.json version was edited (e.g. '0.0.0-local'); pnpm overrides replacing version metadata; partially deleted node_modules.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of vercel/next.js@34433fd12e (2026-09-20). Data as JSON: /api/errors/44d6a1cc09234bb8. Report an issue: GitHub.

Appendix: source

Thrown at packages/next/src/lib/upgrade/prepare-upgrade.ts:44

    targetRequest !== 'latest' &&
    targetRequest !== 'future'
  ) {
    throw new Error(
      `Unsupported AI upgrade type ${JSON.stringify(targetRequest)}. Expected "security", "latest", or "future".`
    )
  }

  // Resolve from the app: the invoking canary is only the upgrade tooling.
  const requireFromApp = createRequire(join(directory, 'package.json'))
  const installedNext = JSON.parse(
    await readFile(requireFromApp.resolve('next/package.json'), 'utf8')
  ) as {
    version: string
  }
  const installedVersion = installedNext.version

  if (!semver.valid(installedVersion)) {
    throw new Error('Could not determine the installed Next.js version.')
  }

  // TODO: Handle prereleases
  if (semver.prerelease(installedVersion)) {
    throw new Error(
      'AI upgrades are not available for prerelease versions of Next.js yet.'
    )
  }

  if (targetRequest === 'latest' || targetRequest === 'future') {
    const url = `${NPM_REGISTRY}next/latest`
    const { value } = await fetchJSON(url)
    const release = value as { version: string } | null

    if (
      !release ||
      !semver.valid(release.version) ||
      semver.prerelease(release.version)

View on GitHub (pinned to 34433fd12e)