How to fix npm ERR! code EPARSE npm ERR! Error parsing configuration in npm
The npm EPARSE error occurs when npm fails to parse a configuration file (package.json or .npmrc), typically due to invalid JSON syntax, malformed key-value pairs, or file encoding issues. This error prevents package installation and other npm operations.
Quick fix
Fixes EPARSE
{
"name": "my-app",
"dependencies": {
"express": "^4.18.0",
}
}- Validate your package.json syntax
- Check your .npmrc file for syntax errors
- Fix file encoding issues
- Remove and regenerate package-lock.json
{"name": "my-app","dependencies": {"express": "^4.18.0",}}npm ERR! code EPARSEnpm ERR! Error parsing configuration
What this error means
npm encountered a syntax error while trying to read and interpret one of its configuration files. This can happen in package.json (JSON syntax error) or in .npmrc files (ini-format syntax error). When npm parses these files, it expects strict formatting—any deviation causes it to throw the EPARSE code.
Typical symptoms
- npm install or npm commands fail with 'npm ERR! code EPARSE Error parsing configuration'
- npm error message indicates the specific file that failed to parse
- Commas appear in unexpected places or are missing from JSON
- .npmrc file contains malformed registry or authentication configurations
- Error appears after editing package.json or .npmrc manually
Common causes
- Trailing commas in package.json after the last dependency, script, or property
- Missing commas between JSON key-value pairs in package.json
- Syntax errors in .npmrc file (incorrect key=value format)
- Invalid JSON in package.json (unclosed braces, quotes, or brackets)
- .npmrc file uses wrong syntax, such as @scope=url instead of @scope:registry=url
- File encoding issues (UTF-16 instead of UTF-8)
- Comments in JSON files (JSON does not support comments)
How to fix "npm ERR! code EPARSE npm ERR! Error parsing configuration"
Open your package.json file and validate it using jsonlint.com or similar.
Example of invalid syntax (trailing comma):
{
"name": "my-app",
"dependencies": {
"express": "^4.18.0",
}
}Correct syntax:
{
"name": "my-app",
"dependencies": {
"express": "^4.18.0"
}
}If you have a .npmrc file, verify its syntax (ini-format, not JSON):
Correct .npmrc syntax:
@my-org:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=YOUR_TOKEN
registry=https://registry.npmjs.org/Common mistakes:
- Using @scope=url instead of @scope:registry=url
- Using registry.com:authToken instead of //registry.com/:_authToken
Ensure the file is saved as UTF-8, not UTF-16.
In VS Code:
1. Open the file
2. Click the encoding selector in the bottom-right corner
3. Select "UTF-8"
4. Save the file
A corrupted package-lock.json can also cause parsing errors:
rm package-lock.json
npm installClear the npm cache to remove any cached corrupt configuration:
npm cache clean --forceInstead of manually editing .npmrc, use npm config:
npm config set registry https://registry.npmjs.org/
npm config set //npm.pkg.github.com/:_authToken=YOUR_TOKENVerify your configuration:
npm config listAdvanced notes
The EPARSE error can originate from multiple sources: package.json uses strict JSON parsing; .npmrc uses ini-format parsing with different rules. npm loads config from multiple files in order: ~/.npmrc, .npmrc in the project root, and ~/.npm/node-gyp/.npmrc, and the first parse error in any causes the failure.
Frequently asked questions
- What does "EPARSE" mean?
- npm encountered a syntax error while trying to read and interpret one of its configuration files. npmrc files (ini-format syntax error). When npm parses these files, it expects strict formatting—any deviation causes it to throw the EPARSE code.
- How do I fix "EPARSE"?
- The npm EPARSE error occurs when npm fails to parse a configuration file (package.json or .npmrc), typically due to invalid JSON syntax, malformed key-value pairs, or file encoding issues. This error prevents package installation and other npm operations.
- What causes "EPARSE"?
- Trailing commas in package.json after the last dependency, script, or property Missing commas between JSON key-value pairs in package.json Syntax errors in .npmrc file (incorrect key=value format)
- Is the "EPARSE" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 📖npm Official Documentation(Official Docs)
- 💬Stack Overflow: npm npm-config-parse-error(Stack Overflow)
- 🐙npm GitHub Issues(GitHub)