The EJSONPARSE error with duplicate key occurs when your package.json contains multiple properties with the same name. This typically happens after git merge conflicts or manual editing errors.
The EJSONPARSE error indicates npm's JSON parser encountered invalid syntax in your package.json file. Unlike JavaScript engines that silently accept duplicate keys (keeping only the last value), npm uses a strict JSON parser that explicitly rejects files containing multiple keys with the same name at the same nesting level. This error commonly surfaces when package.json has been corrupted through incomplete merge conflict resolution, where markers like `<<<<<<<`, `=======`, and `>>>>>>>` remain in the file, or when multiple sections like `dependencies` appear twice due to a faulty merge. The parser halts immediately upon finding duplicate keys, preventing any npm command from executing.
Copy your package.json contents into a JSON validator like JSONLint to identify the exact location of duplicate keys or syntax errors:
1. Go to https://jsonlint.com/
2. Paste your entire package.json
3. Click "Validate JSON"
4. Look for "Duplicate key" warnings in the results
Open package.json and search for common duplicated sections. Each of these should appear only once:
# Search for potential duplicates
grep -n '"dependencies"' package.json
grep -n '"devDependencies"' package.json
grep -n '"scripts"' package.json
grep -n '"name"' package.jsonIf any search returns multiple line numbers, you have duplicates to merge.
Check for and remove any leftover merge conflict markers:
# Search for conflict markers
grep -n "<<<<<<<\|=======\|>>>>>>>" package.jsonIf found, edit package.json to:
1. Remove all <<<<<<< lines
2. Remove all ======= lines
3. Remove all >>>>>>> lines
4. Keep only the correct version of conflicting code
Check for missing or trailing commas:
Missing comma (invalid):
{
"name": "my-app"
"version": "1.0.0"
}Trailing comma (invalid in JSON):
{
"name": "my-app",
"version": "1.0.0",
}Correct:
{
"name": "my-app",
"version": "1.0.0"
}If you have two dependency sections, combine them into one:
Before (invalid):
{
"dependencies": {
"express": "^4.18.0"
},
"dependencies": {
"lodash": "^4.17.0"
}
}After (valid):
{
"dependencies": {
"express": "^4.18.0",
"lodash": "^4.17.0"
}
}After fixing the JSON, clear npm cache and reinstall:
# Clear npm cache
npm cache clean --force
# Remove existing artifacts
rm -rf node_modules package-lock.json
# Reinstall dependencies
npm installIf the file is too corrupted to fix manually, regenerate it:
# Backup current file
mv package.json package.json.bak
# Create fresh package.json
npm init -y
# Manually copy dependencies from backup
# Then reinstall
npm installFor CI/CD pipelines, add a pre-merge validation step that checks package.json syntax before allowing merges. Tools like find-duplicated-property-keys can programmatically detect duplicate keys. Modern IDEs like VS Code and WebStorm highlight duplicate JSON keys in real-time—ensure JSON validation is enabled in your editor settings.
In Docker builds, this error halts the entire build process. Validate package.json on the host machine before the COPY command in your Dockerfile to catch errors earlier in the development cycle.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error