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.

Fix it fast

Most likely: package.json is not valid JSON, often because of a trailing comma, comment, quote error, or unresolved merge marker.

1. Confirm this is your error
npm ERR! code EJSONPARSE
npm ERR! Invalid package.json: JSONParseError
npm ERR! JSON.parse Failed to parse JSON data.
2. Check the cause
node -e "JSON.parse(require('fs').readFileSync('package.json','utf8')); console.log('valid json')"
sed -n '1,120p' package.json
git diff -- package.json
3. Apply the safe fix
# Fix package.json so it is strict JSON: no comments, no trailing commas, no merge markers.
node -e "JSON.parse(require('fs').readFileSync('package.json','utf8')); console.log('valid json')"
npm install
4. Verify it works
node -e "JSON.parse(require('fs').readFileSync('package.json','utf8')); console.log('valid json')"
npm install
Don't use unsafe shortcuts
  • Do not add comments to package.json, JSON does not allow them.
  • Do not leave conflict markers like <<<<<<< or ======= after a merge.
  • Do not debug network, registry, or auth settings until package.json parses.

What Is Wrong With the JSON

npm is failing before it can do any useful work because one of the JSON files it depends on does not parse cleanly.

Fix the JSON syntax first

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 the JSON No Longer Parses

Usually this comes down to package.json contains invalid JSON (trailing commas, comments, or a broken merge), or the file encoding is corrupted (rare).

Verify the JSON Parses Cleanly Again

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

Check the file and parser location from the error output

Repeat the failure from the same environment with verbose or debug logging so you can confirm the first actionable error, not just the final summary line.

Validate the local configuration and the remote target separately. That usually narrows the problem much faster than retrying the full workflow.

Compare the failing environment with one that works, paying attention to credentials, runtime versions, proxy settings, and filesystem paths.

How npm validates the command before it runs

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

Prevent It From Coming Back

To prevent this, use a JSON-aware formatter/validator in CI, and avoid manual edits that introduce comments or trailing commas.

Docs and source code

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