vuejs/vue-cli · error · Error

The package.json file at '${packagePath}' does not exist

Error message

The package.json file at '${packagePath}' does not exist

What it means

Thrown by getPackageJson in getPkg.js when fs.readFileSync fails to read the package.json file at the resolved path. The catch block converts any file-system error (ENOENT, EACCES, etc.) into this message. This function is used to load the project's package.json during CLI operations.

Source

Thrown at packages/@vue/cli/lib/util/getPkg.js:14

// Get the package.json containing all the `vue-cli-pluin-*` dependencies
// See issue #1815

const fs = require('fs')
const path = require('path')

function getPackageJson (projectPath) {
  const packagePath = path.join(projectPath, 'package.json')

  let packageJson
  try {
    packageJson = fs.readFileSync(packagePath, 'utf-8')
  } catch (err) {
    throw new Error(`The package.json file at '${packagePath}' does not exist`)
  }

  try {
    packageJson = JSON.parse(packageJson)
  } catch (err) {
    throw new Error('The package.json is malformed')
  }

  return packageJson
}

module.exports = function getPkg (context) {
  const pkg = getPackageJson(context)
  if (pkg.vuePlugins && pkg.vuePlugins.resolveFrom) {
    return getPackageJson(path.resolve(context, pkg.vuePlugins.resolveFrom))
  }
  return pkg
}

View on GitHub (pinned to 7eb93c169c)

Solutions

  1. Ensure you are running the command in the project root that contains package.json.
  2. Check that package.json exists: `ls package.json`.
  3. If vuePlugins.resolveFrom is set, verify that the target path exists and contains a valid package.json.
  4. Check file permissions: `ls -la package.json`.

Example fix

# before
$ cd /wrong/dir && vue serve
Error: package.json does not exist
# after
$ cd /path/to/vue-project
$ ls package.json
$ vue serve
Defensive patterns

Strategy: validation

Validate before calling

const { existsSync } = require('fs');
const path = require('path');
const packagePath = path.join(projectPath, 'package.json');
if (!existsSync(packagePath)) {
  console.error(`No package.json found at ${packagePath}. Run this command in a project root.`);
  process.exit(1);
}

Try / catch

try {
  const pkg = getPkg(context);
} catch (e) {
  if (e.message.includes('does not exist')) {
    console.error('package.json not found. Ensure you are in the project root.');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running a Vue CLI command in a directory that has no package.json, or where the project path resolves incorrectly (e.g., via vuePlugins.resolveFrom pointing to a non-existent directory). Also when file permissions prevent reading.

Common situations: Running `vue` commands outside a Vue project directory. Corrupted or deleted package.json. A vuePlugins.resolveFrom field in package.json pointing to a path that no longer exists. Permission issues on the file system.

Related errors


AI-assisted analysis of vuejs/vue-cli@7eb93c169c (2026-08-13). Data as JSON: /api/errors/7994452fa0151550. Report an issue: GitHub.