How to fix npm ERR! code EJSONPARSE in npm
The EJSONPARSE error occurs when npm encounters invalid JSON in package.json or another JSON configuration file. This is usually caused by syntax errors like missing commas, brackets, or quotes.
Quick fix
Fixes npm ERR! code EJSONPARSE
npm install
# Output shows:
# npm ERR! JSON.parse Failed to parse json
# npm ERR! JSON.parse Unexpected token } in JSON at position 234- Locate the error
- Validate JSON syntax
- Check for trailing commas
- Check for comments
npm install# Output shows:# npm ERR! JSON.parse Failed to parse json# npm ERR! JSON.parse Unexpected token } in JSON at position 234npm ERR! code EJSONPARSE
What this error means
EJSONPARSE indicates that npm failed to parse a JSON file, most commonly package.json. JSON has strict syntax requirements - even small errors like a trailing comma, missing quote, or extra bracket will cause parsing to fail. This error can occur in package.json, package-lock.json, .npmrc, or any other JSON file that npm tries to read during its operation.
Typical symptoms
- npm commands fail immediately with JSON parse error
- Error points to specific line and column
- Recently edited package.json
- Merge conflict markers in JSON files
- Copy-pasted JSON with hidden characters
- Comments added to JSON file
Common causes
- Trailing comma after last item
- Missing comma between items
- Missing or extra brackets/braces
- Single quotes instead of double quotes
- Unquoted property names
- Comments in JSON (not allowed)
- Merge conflict markers
- BOM or hidden characters
How to fix "npm ERR! code EJSONPARSE"
Read the error message carefully:
npm install
# Output shows:
# npm ERR! JSON.parse Failed to parse json
# npm ERR! JSON.parse Unexpected token } in JSON at position 234The position helps locate the error.
Use a JSON validator:
# Using jq
jq . package.json
# Using Node.js
node -e "require('./package.json')"
# Or use online validators like jsonlint.comJSON doesn't allow trailing commas:
// WRONG
{
"name": "pkg",
"version": "1.0.0", // <-- trailing comma ERROR
}
// CORRECT
{
"name": "pkg",
"version": "1.0.0"
}JSON doesn't support comments:
// WRONG
{
// This is a comment - NOT ALLOWED
"name": "pkg"
}
// CORRECT - no comments
{
"name": "pkg"
}JSON requires double quotes:
// WRONG
{
'name': 'pkg',
name: "pkg"
}
// CORRECT
{
"name": "pkg"
}Look for conflict markers:
// WRONG - contains merge markers
{
"name": "pkg",
<<<<<<< HEAD
"version": "1.0.0"
=======
"version": "2.0.0"
>>>>>>> branch
}Resolve conflicts and remove markers.
Advanced notes
Use an editor with JSON validation (VS Code has built-in support). Enable format-on-save for JSON files. Consider using jsonc (JSON with comments) for config files that support it, but remember package.json must be strict JSON. For programmatic JSON generation, always use JSON.stringify() rather than string concatenation.
Frequently asked questions
- What does "npm ERR! code EJSONPARSE" mean?
- json. JSON has strict syntax requirements - even small errors like a trailing comma, missing quote, or extra bracket will cause parsing to fail. npmrc, or any other JSON file that npm tries to read during its operation.
- How do I fix "npm ERR! code EJSONPARSE"?
- The EJSONPARSE error occurs when npm encounters invalid JSON in package.json or another JSON configuration file. This is usually caused by syntax errors like missing commas, brackets, or quotes.
- What causes "npm ERR! code EJSONPARSE"?
- Trailing comma after last item Missing comma between items Missing or extra brackets/braces
- Is the "npm ERR! code EJSONPARSE" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐
- ๐