Skip to content

[BUG] npm view package@latest exits with code 0 and no output if latest tag does not exist #6408

Closed as not planned
@mcous

Description

@mcous

Is there an existing issue for this?

  • I have searched the existing issues

I found #4029, but the issue was closed with no resolution. I am requesting a different "expected behavior" than that ticket.

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

If the latest tag does not exist, npm view package and npm view package@latest will exit with code 0 and empty output.

This causes problems with tools / CI flows that use npm view to list existing versions of a package, especially with third-party registries.

Expected Behavior

I would expect an E404, like what happens with you reference a different tag that does not exist, like npm view example@foobar.

Steps To Reproduce

This is a bit difficult to reproduce, because the npm registry appears to automatically create the latest tag for a newly published package, even if you publish to a different tag.

The GitHub NPM Package Repository, however, does not do this, so it's possible to create a package that has no latest tag. I have created a public package that exhibits this behavior.

This reproduction requires a GitHub Personal Access token configured for the //npm.pkg.github.com/:_authToken config setting.

# exit code 0
❯ npm_config_registry=https://npm.pkg.github.com/ npm view "@tracespace/parser@next" versions dist-tags
versions = '5.0.0-alpha.0'
dist-tags = { next: '5.0.0-alpha.0' }

# exit code 1
❯ npm_config_registry=https://npm.pkg.github.com/ npm view "@tracespace/parser@not-a-tag" versions dist-tags
npm ERR! code E404
npm ERR! 404 No match found for version not-a-tag
npm ERR! 404
npm ERR! 404  '@not-a-tag' is not in this registry.
npm ERR! 404 This package name is not valid, because
npm ERR! 404  1. name can only contain URL-friendly characters
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in: /Users/mc/.npm/_logs/2023-04-29T17_08_32_549Z-debug-0.log

# exit code 0, no output on stdout nor stderr
❯ npm_config_registry=https://npm.pkg.github.com/ npm view "@tracespace/parser@latest" versions dist-tags

Environment

  • npm: 9.6.5
  • Node.js: 18.13.0
  • OS Name: macOS 13.3.1 (22E261)
  • System Model Name: iMac Pro
  • npm config:
; "user" config from /Users/mc/.npmrc

//npm.pkg.github.com/:_authToken = (protected)

; node bin location = /Users/mc/.nvs/node/18.13.0/x64/bin/node
; node version = v18.13.0
; npm local prefix = /Users/mc/projects/tracespace/packages/parser
; npm version = 9.6.5
; cwd = /Users/mc/projects/tracespace/packages/parser
; HOME = /Users/mc
; Run `npm config ls -l` to show all defaults.

; "publishConfig" from /Users/mc/projects/tracespace/packages/parser/package.json
; This set of config values will be used at publish-time.

access = "public"
registry = "https://npm.pkg.github.com/"
tag = "next"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 9.xwork is associated with a specific npm 9 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions