Skip to content

fix: handle unpublished packages with undefined packument versions - #458

Merged
fregante merged 5 commits into
npmgraph:mainfrom
isaim0011:fix/packument-versions-undefined
Oct 3, 2026
Merged

fregante merged 5 commits into
npmgraph:mainfrom
isaim0011:fix/packument-versions-undefined

Conversation

@isaim0011

@isaim0011 isaim0011 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a package is unpublished on npm (such as asdasd), the npm registry returns HTTP 200 with metadata containing time.unpublished, but packument.versions is undefined.

Previously, selectVersion attempted to call Object.keys(packument.versions) directly, causing an uncaught runtime TypeError:
TypeError: undefined is not an object (evaluating 'Object.keys(packument.versions)')

Changes

  1. Safely check for packument.versions in selectVersion, returning undefined instead of throwing a TypeError.
  2. In fetchModuleFromNPM, check packument.time.unpublished to throw a clear error (${moduleName} has been unpublished).
  3. If a module has no versions matching or published, throw a descriptive error (${moduleName} has no published versions).
  4. Added unit tests in lib/selectVersion.test.ts to verify dist-tag selection, semver resolution, and unpublished/missing versions.

@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

@isaim0011 is attempting to deploy a commit to the Broofa Personal Team on Vercel.

A member of the Team first needs to authorize it.

@fregante

Copy link
Copy Markdown
Member

Thanks for the PR! Can you push an empty commit? I'm trying something out

@isaim0011

Copy link
Copy Markdown
Contributor Author

Done! Pushed an empty commit (\24a4042). Let me know if you need anything else!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

All reviewed changes are covered and no unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes crashes when npm returns unpublished package metadata without versions, with clearer errors and expanded tests.

Changes:

  • Safely handles missing package versions.
  • Reports unpublished and versionless packages clearly.
  • Adds version-selection unit tests.
File Summary
lib/​selectVersion.ts Safely selects versions when metadata is incomplete.
lib/​selectVersion.test.ts Tests tags, semver ranges, and missing versions.
lib/​ModuleCache.ts Adds clearer unpublished and version errors.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@fregante
fregante enabled auto-merge (squash) October 3, 2026 09:27
@fregante
fregante merged commit a9a7690 into npmgraph:main Oct 3, 2026
3 of 4 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.

undefined is not an object (evaluating 'Object.keys(packument.versions)')

4 participants