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.jsonPrevent recurrence
- Resolve merge conflicts in
package.jsonfully - no markers left behind. - Edit dependencies with
npm install <pkg>rather than hand-editing JSON. - Add a JSON-lint or
npm pkg fixcheck in CI/pre-commit.
How to prevent it
- Validate package.json in CI before installing.
- Use
npm install/npm pkg setinstead of hand-editing. - Catch merge-conflict markers in pre-commit hooks.
Related guides
npm EUSAGE "Usage:" - Fix Invalid npm Command or Flags in CIFix npm EUSAGE in CI - npm rejected the command because of an unknown flag, wrong arguments, or a typo. Read…
npm "warn config … deprecated" - Fix Deprecated .npmrc Settings in CIFix npm "npm warn config … is deprecated" noise in CI - old .npmrc keys (e.g. cache-min, production, optional…
npm ELOCKVERIFY / "Errors were found in your package-lock.json" - Fix in CIFix npm lockfile verification errors in CI - "Errors were found in your package-lock.json, run npm install to…