Error Knowledge Base NPM EJSONPARSE

npm ERR! code EJSONPARSE

npm could not parse package.json because the JSON is invalid, such as trailing commas, mismatched quotes, or broken syntax.

What This Error Means

npm could not parse package.json because the JSON is invalid, such as trailing commas, mismatched quotes, or broken syntax.

How to Fix It

Open package.json and 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.json contains 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.

Examples

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

npm reads package.json to 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' }
      )
    }

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

Join our mailing list