Skip to content

package.json: reject empty "version" string - #6421

Merged
hyperupcall merged 2 commits into
SchemaStore:masterfrom
simin-yuan:package-version-min-length
Sep 28, 2026
Merged

hyperupcall merged 2 commits into
SchemaStore:masterfrom
simin-yuan:package-version-min-length

Conversation

@simin-yuan

Copy link
Copy Markdown
Contributor

"version": "" currently validates against the package.json schema, but npm refuses it:

$ npm pack --dry-run
npm error Invalid package, must have name and version

An empty string is also not parsable by node-semver, which is what the field's own description requires. This adds "minLength": 1 to version, matching the existing constraint on name.

Scope is deliberately minimal:

  • version stays optional (private packages and workspace roots legitimately omit it); only the empty string is rejected.
  • No semver pattern is added, to avoid rejecting any version string node-semver accepts.

Tests: new negative test src/negative_test/package/version-empty-string.json. It validates against the current schema and is rejected with this change; the existing positive and negative tests under package/ are unaffected.

Found by mutation-testing the schema against a real package.json with greencheck; details in its third-party case study.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by @madskristensen and @hyperupcall - if they write a comment saying "LGTM" then it will be merged.

@hyperupcall

Copy link
Copy Markdown
Member

Thanks, this is great.

@hyperupcall
hyperupcall merged commit a83ce6f into SchemaStore:master Sep 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants