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 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
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm