Error Knowledge Base NPM EJSONPARSE

npm ERR! code EJSONPARSE

npm could not parse `package.json` (invalid JSON).

Affected versions: All supported npm versions.

What This Error Means

npm could not parse package.json (invalid JSON).

How to Fix It

  1. Open package.json and validate JSON syntax (no comments, no trailing commas).
  2. If this happened after a merge, re-run the merge and resolve JSON correctly.
  3. Retry npm install.

Why It Happens

  • package.json contains invalid JSON (trailing commas, comments, or a broken merge).
  • The file encoding is corrupted (rare).

How to Verify

  1. Run node -e "JSON.parse(require(\"fs\").readFileSync(\"package.json\",\"utf8\"))" and confirm it succeeds.
  2. Re-run the original npm command.

Common CLI Output

npm ERR! code EJSONPARSE
npm ERR! Invalid package.json: JSONParseError
npm ERR! JSON.parse Failed to parse JSON data.
npm ERR! JSON.parse Unexpected token

How npm executes the command

  1. npm reads package.json to determine dependencies, scripts, and configuration.
  2. If the JSON cannot be parsed, npm cannot proceed.

Prevention Tips

  • Use a JSON-aware formatter/validator in CI.
  • Avoid manual edits that introduce comments or trailing commas.

Where This Can Be Triggered

github.com/npm/cli/blob/417daa72b09c5129e7390cd12743ef31bf3ddb83/lib/commands/ls.js

Open-source npm CLI code reference tied to this error code. - GitHub

    if (rootError) {
      throw Object.assign(
        new Error('Failed to parse root package.json'),
        { code: 'EJSONPARSE' }
      )
    }

Need help or found a mistake? Contact RepoFlow support for questions.

Join our mailing list