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.
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.
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 listThe 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.
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm