How to fix npm ERR! code EINVALIDVERSION npm ERR! Invalid version: "not.a.version" in npm
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.
Quick fix
Fixes EINVALIDVERSION
{
"name": "my-package",
"version": "1.0.0"
}- Check your package.json version
- Fix common invalid formats
- Fix pre-release versions
- Clean install if error is in dependencies
{"name": "my-package","version": "1.0.0"}npm ERR! code EINVALIDVERSIONnpm ERR! Invalid version: "not.a.version"
What this error means
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.
Typical symptoms
- npm install fails with 'Invalid version' error
- npm publish rejects your package
- npm audit crashes on packages with bad version history
- Error shows the specific invalid version string
- Old/inherited projects fail to install
- Version field in package.json highlighted as error
Common causes
- Version missing patch number (1.0 instead of 1.0.0)
- Version has four parts (1.0.0.0)
- Version contains letters in wrong format (1.0.0rc1 instead of 1.0.0-rc.1)
- Version field contains URL or path
- Pre-release format incorrect (1.0.0-01 instead of 1.0.0-1)
- Snapshot or development versions from other ecosystems
How to fix "npm ERR! code EINVALIDVERSION npm ERR! Invalid version: "not.a.version""
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)Advanced notes
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
Frequently asked questions
- What does "EINVALIDVERSION" mean?
- This error occurs when npm encounters a version string that doesn't conform to semantic versioning (semver) format. 0). json's "version" field or in dependency specifications.
- How do I fix "EINVALIDVERSION"?
- 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.
- What causes "EINVALIDVERSION"?
- Version missing patch number (1.0 instead of 1.0.0) Version has four parts (1.0.0.0) Version contains letters in wrong format (1.0.0rc1 instead of 1.0.0-rc.1)
- Is the "EINVALIDVERSION" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 🔗
- 🔗
- 💬Stack Overflow: npm err invalid version on npm install(Stack Overflow)