You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] npm view --json outputs illegal JSON for existing package but non-existent version #3184
npm view <package>@<version> --json returns an empty or white-space string when answering a query for a package which does exist, but a version descriptor which has no matches. This is illegal JSON and attempting to JSON.parse it throws an error.
Expected Behavior:
npm view <package>@<version> --json should return valid JSON in this case: either null or something that is contextually relevant to the kind of query, such as perhaps an empty array []. E.g.
It looks like this problem isn't specific to the --json flag. Without the --json flag, as of npm 7.20.3, using npm view react@9999 will exit successfully instead of emitting an error and exiting with a non-zero exit code.
All of these cases now correctly set the exit code to 1 and show the relevant error. In --json mode that error is present in the json output.
❯ npm --version
10.7.0
❯ npm view npm@11 --json
npm error code E404
npm error 404 No match found for version 11
npm error 404
npm error 404 'npm@11' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
{
"error": {
"code": "E404",
"summary": "No match found for version 11",
"detail": "\n 'npm@11' is not in this registry.\n\nNote that you can also install from a\ntarball, folder, http url, or git url."
}
}
npm error A complete log of this run can be found in: /Users/lukekarrys/.npm/_logs/2024-05-13T22_12_44_503Z-debug-0.log
❯ npm view npm@11 version --json
npm error code E404
npm error 404 No match found for version 11
npm error 404
npm error 404 'npm@11' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
{
"error": {
"code": "E404",
"summary": "No match found for version 11",
"detail": "\n 'npm@11' is not in this registry.\n\nNote that you can also install from a\ntarball, folder, http url, or git url."
}
}
npm error A complete log of this run can be found in: /Users/lukekarrys/.npm/_logs/2024-05-13T22_13_04_350Z-debug-0.log
❯ npm view npm@11
npm error code E404
npm error 404 No match found for version 11
npm error 404
npm error 404 'npm@11' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /Users/lukekarrys/.npm/_logs/2024-05-13T22_13_19_311Z-debug-0.log
❯ npm view npm@11 version
npm error code E404
npm error 404 No match found for version 11
npm error 404
npm error 404 'npm@11' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /Users/lukekarrys/.npm/_logs/2024-05-13T22_13_27_269Z-debug-0.log
Activity
varungandhi-src commentedon Nov 8, 2021
It looks like this problem isn't specific to the
--jsonflag. Without the--jsonflag, as ofnpm7.20.3, usingnpm view react@9999will exit successfully instead of emitting an error and exiting with a non-zero exit code.lukekarrys commentedon May 13, 2024
All of these cases now correctly set the exit code to
1and show the relevant error. In--jsonmode that error is present in the json output.