How to fix npm ERR! package.json must have version in npm

npmBEGINNERMEDIUMUpdated Dec 6, 2025ยท 198 views

The "Missing version" error occurs when package.json lacks the required "version" field. Every npm package must have a valid semantic version number.

Quick fix

Fixes npm ERR! package.json must have version

{
  "name": "your-package",
  "version": "1.0.0"
}
  1. Add version field
  2. Use npm init
  3. Use npm version
  4. Understand semver format
npm โ€” error
{
"name": "your-package",
"version": "1.0.0"
}
npm ERR! package.json must have version

What this error means

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.

Typical symptoms

  • npm commands fail mentioning version required
  • package.json created without version
  • Version field accidentally deleted
  • Invalid version format
  • Merge conflict removed version
  • Template file incomplete

Common causes

  1. Manual package.json creation without version
  2. Accidental deletion
  3. Merge conflict resolution error
  4. Invalid version format (not semver)
  5. JSON parsing error hiding field
  6. Empty or whitespace version

How to fix "npm ERR! package.json must have version"

1Add version field

Include valid semver version:

json
{
  "name": "your-package",
  "version": "1.0.0"
}

Start with 1.0.0 or 0.1.0 for initial development.

2Use npm init

Create valid package.json:

bash
# Interactive
npm init

# With defaults (version: 1.0.0)
npm init -y
3Use npm version

Set or update version properly:

bash
# Set specific version
npm version 1.0.0 --no-git-tag-version

# Or use from-git for git tag-based versioning
npm version from-git
4Understand semver format

Valid version formats:

json
"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 development

Format: MAJOR.MINOR.PATCH

5Restore from git

If version was deleted:

bash
git diff package.json
git checkout HEAD -- package.json
6Fix invalid version

Ensure version is valid semver:

json
// WRONG
"version": "1"          // Too short
"version": "v1.0.0"     // No "v" prefix
"version": "1.0"        // Need patch

// CORRECT
"version": "1.0.0"

Advanced notes

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.

Frequently asked questions

What does "npm ERR! package.json must have version" mean?
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.
How do I fix "npm ERR! package.json must have version"?
The "Missing version" error occurs when package.json lacks the required "version" field. Every npm package must have a valid semantic version number.
What causes "npm ERR! package.json must have version"?
Manual package.json creation without version Accidental deletion Merge conflict resolution error
Is the "npm ERR! package.json must have version" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading