The "Missing version" error occurs when package.json lacks the required "version" field. Every npm package must have a valid semantic version number.
Fixes npm ERR! package.json must have version
{
"name": "your-package",
"version": "1.0.0"
}{"name": "your-package","version": "1.0.0"}npm ERR! package.json must have version
Along with name, version is a required field in package.json. npm uses semantic versioning (semver) to track package versions, manage updates, and resolve dependencies. Without a version, npm cannot determine if your package is newer or older than installed versions, cannot properly resolve dependency trees, and cannot publish to the registry.
Include valid semver version:
{
"name": "your-package",
"version": "1.0.0"
}Start with 1.0.0 or 0.1.0 for initial development.
Create valid package.json:
# Interactive
npm init
# With defaults (version: 1.0.0)
npm init -ySet or update version properly:
# Set specific version
npm version 1.0.0 --no-git-tag-version
# Or use from-git for git tag-based versioning
npm version from-gitValid version formats:
"version": "1.0.0" // Standard
"version": "1.0.0-beta.1" // Prerelease
"version": "1.0.0-rc.1" // Release candidate
"version": "0.0.1" // Early developmentFormat: MAJOR.MINOR.PATCH
If version was deleted:
git diff package.json
git checkout HEAD -- package.jsonEnsure version is valid semver:
// WRONG
"version": "1" // Too short
"version": "v1.0.0" // No "v" prefix
"version": "1.0" // Need patch
// CORRECT
"version": "1.0.0"Use npm version commands (major, minor, patch) to increment versions properly. In CI/CD, consider semantic-release for automated version management. The version field is immutable after publishing - you cannot republish the same version with different content. Use 0.x.x versions during development to indicate instability.