The EINVALIDVERSION error occurs when package.json contains a version that doesn't follow semantic versioning format. Use the standard X.Y.Z format (e.g., '1.0.0') instead of incomplete or malformed versions.
This error occurs when npm encounters a version string that doesn't conform to semantic versioning (semver) format. Valid versions must follow the MAJOR.MINOR.PATCH pattern (e.g., 1.0.0). The error appears in your package.json's "version" field or in dependency specifications. Common invalid formats include two-part versions (1.0), versions with 'v' prefix (v1.0.0), snapshot versions (1.0.0-SNAPSHOT), or completely non-numeric strings. npm uses strict semver parsing to ensure version compatibility across the ecosystem.
Look at the version field:
{
"name": "my-package",
"version": "1.0.0"
}It must be exactly three numbers separated by dots. No 'v' prefix, no extra parts.
Convert invalid versions to valid semver:
| Invalid | Valid |
|---------|-------|
| 1.0 | 1.0.0 |
| v1.0.0 | 1.0.0 |
| 1.0.0.0 | 1.0.0 |
| 1.0.0rc1 | 1.0.0-rc.1 |
| 1.0.0-01 | 1.0.0-1 |
| dev-master | 0.0.0-dev |
| SNAPSHOT | 0.0.0-snapshot |
Pre-release versions have a specific format:
// Invalid
"version": "1.0.0rc1"
"version": "1.0.0-01"
// Valid
"version": "1.0.0-rc.1"
"version": "1.0.0-alpha.1"
"version": "1.0.0-beta.2"Pre-release identifiers are separated by dots and must not have leading zeros.
If the invalid version is in a dependency:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installThis forces npm to fetch fresh package metadata.
If npm audit crashes on historical invalid versions:
npm install --no-auditSome old packages have invalid versions in their history that break audit.
Check if a version is valid:
node -e "console.log(require('semver').valid('1.0.0'))"
# Output: 1.0.0 (valid) or null (invalid)Or use npx:
npx semver 1.0.0
# Output: 1.0.0 (valid) or error (invalid)Semantic versioning (semver) rules:
- MAJOR: Breaking changes
- MINOR: New features, backwards compatible
- PATCH: Bug fixes, backwards compatible
Build metadata is allowed but ignored for precedence:
1.0.0+build.123 (valid, +metadata is ignored in comparisons)If you're migrating from another ecosystem:
- Maven: 1.0-SNAPSHOT → 1.0.0-snapshot
- Python: 1.0rc1 → 1.0.0-rc.1
- Ruby: 1.0.pre → 1.0.0-pre
For automated version management, consider tools like:
- npm version patch/minor/major
- semantic-release
- standard-version
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