What This Error Means
npm could not parse package.json (invalid JSON).
How to Fix It
- Open
package.jsonand validate JSON syntax (no comments, no trailing commas). - If this happened after a merge, re-run the merge and resolve JSON correctly.
- Retry
npm install.
Why It Happens
package.jsoncontains invalid JSON (trailing commas, comments, or a broken merge).- The file encoding is corrupted (rare).
How to Verify
- Run
node -e "JSON.parse(require(\"fs\").readFileSync(\"package.json\",\"utf8\"))"and confirm it succeeds. - Re-run the original npm command.
Common CLI Output
npm ERR! code EJSONPARSEnpm ERR! Invalid package.json: JSONParseErrornpm ERR! JSON.parse Failed to parse JSON data.npm ERR! JSON.parse Unexpected token How npm executes the command
- npm reads
package.jsonto determine dependencies, scripts, and configuration. - 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' }
)
}