Skip to content
Latchkey

npm EJSONPARSE "Failed to parse JSON" - Fix a Broken package.json in CI

EJSONPARSE means npm could not parse your package.json (or another JSON file) because it is not valid JSON. The fix is to correct the syntax - this is never a transient error.

What this error means

npm fails immediately with npm error code EJSONPARSE and a position in package.json. Nothing installs because npm cannot read the manifest at all.

npm output
npm error code EJSONPARSE
npm error JSON.parse Failed to parse JSON data.
npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.
npm error JSON.parse Unexpected token } in JSON at position 412 while parsing ...

Common causes

Invalid JSON syntax

A trailing comma, a single-quoted string, a comment, or a missing brace makes package.json invalid JSON. npm requires strict JSON, not JavaScript.

Unresolved merge conflict markers

Leftover <<<<<<<, =======, or >>>>>>> markers from a bad merge corrupt the file and break parsing.

How to fix it

Find and fix the invalid JSON

Validate the file and correct the offending syntax.

Terminal
node -e "JSON.parse(require('fs').readFileSync('package.json','utf8'))"
# or
npx jsonlint package.json

Prevent recurrence

  1. Resolve merge conflicts in package.json fully - no markers left behind.
  2. Edit dependencies with npm install <pkg> rather than hand-editing JSON.
  3. Add a JSON-lint or npm pkg fix check in CI/pre-commit.

How to prevent it

  • Validate package.json in CI before installing.
  • Use npm install/npm pkg set instead of hand-editing.
  • Catch merge-conflict markers in pre-commit hooks.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →