vuejs/vue-cli · error · Error

The package.json is malformed

Error message

The package.json is malformed

What it means

Thrown by getPackageJson in getPkg.js when the package.json file exists and is readable but fails JSON.parse — meaning the file content is not valid JSON. The catch wraps any parse error (unexpected token, trailing comma, etc.) into this generic message.

Source

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

// 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. Validate the JSON: `node -e "JSON.parse(require('fs').readFileSync('package.json','utf8'))"` or use an online JSON validator.
  2. Common fixes: remove trailing commas, ensure all keys and string values use double quotes, remove comments.
  3. Check for merge conflict markers (<<<<, ====, >>>>) and resolve them.
  4. Run `npm install` — npm itself will often report the exact parse error location.

Example fix

// before (package.json)
{
  "name": "my-app",
  "version": "1.0.0",   <-- trailing comma
}
// after
{
  "name": "my-app",
  "version": "1.0.0"
}
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
try {
  JSON.parse(fs.readFileSync('package.json', 'utf-8'));
} catch (e) {
  console.error('package.json is invalid JSON:', e.message);
}

Try / catch

try {
  const pkg = getPkg(context);
} catch (e) {
  if (e.message === 'The package.json is malformed') {
    console.error('Fix package.json JSON syntax. Run: node -e "JSON.parse(require(\'fs\').readFileSync(\'package.json\',\'utf8\'))"');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running a Vue CLI command in a project whose package.json contains invalid JSON: unquoted keys, trailing commas, single-quoted strings, comments, or corrupted/truncated content.

Common situations: Manual editing of package.json introduced a syntax error (e.g., trailing comma, missing quote). A merge conflict left conflict markers in the file. A tool or editor accidentally corrupted the file. Copy-pasting from documentation that used JS object shorthand.

Understand the failure class

Related errors


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