getting an error as Unexpected end of JSON input
There's not enough info here to help you.
We'll need your terminal output and your system settings at least to take a look at this, @suyogn
Closing this for lack of information, @suyogn feel free to open this again if you feel like you need more help.
@suyogn I ran into this same issue today. It was caused by me trying to publish a pre-release version of a package that did not yet exist in the registry. Publishing to a non-pre release version fixed this for me. np tries to JSON.parse a list of dist tags from npm, but since there aren't any yet npm throws an error.
Ah that's interesting @hgascoigne . We should not throw an error like unexpected JSON in that case, but actually throw an error saying there are no tags to parse from the npm registry.
I think this is a simple fix. A good PR would be welcome for the same.
So, I played around with reproducing this bug and was not able to.
When i tried to publish a pre-release of an unpublished package on npm, np ran without any complications.
Also, the function we use to parse the npm tags has methods to handle errors, and returns next in case there are no tags to parse from the npm registry.
@hgascoigne , any more pointers on how to reproduce this would be helpful.
Sure, happy to provide some more details.
Reproduction:
package.json.
{
"name": "hayden-test-repo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": ""
},
"author": "",
"license": "ISC"
}
np. Here's a screenshot of my selected options:
Error
Inspecting np, execa throws the following error because the npm view command fails. np then runs into issues because error.stdout is an empty string so JSON.parse on this line fails.
{
"shortMessage": "Command failed with exit code 1: npm view --json hayden-test-repo dist-tags",
"command": "npm view --json hayden-test-repo dist-tags",
"exitCode": 1,
"stdout": "",
"stderr": "npm ERR! code E404\nnpm ERR! 404 Not Found - GET https://registry.npmjs.org/hayden-test-repo - Not found\nnpm ERR! 404 \nnpm ERR! 404 'hayden-test-repo@latest' is not in the npm registry.\nnpm ERR! 404 You should bug the author to publish it (or use the name yourself!)\nnpm ERR! 404 \nnpm ERR! 404 Note that you can also install from a\nnpm ERR! 404 tarball, folder, http url, or git url.\n{\n \"error\": {\n \"code\": \"E404\",\n \"summary\": \"Not Found - GET https://registry.npmjs.org/hayden-test-repo - Not found\",\n \"detail\": \"\\n 'hayden-test-repo@latest' is not in the npm registry.\\nYou should bug the author to publish it (or use the name yourself!)\\n\\nNote that you can also install from a\\ntarball, folder, http url, or git url.\"\n }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR! /Users/hayden/.npm/_logs/2021-04-12T14_41_53_367Z-debug.log",
"failed": true,
"timedOut": false,
"isCanceled": false,
"killed": false
}
Solution
I see the JSON formatted error that I think np is looking for but it lives in error.stderr and is wrapped with plain text so simply changing the line to JSON.parse(error.stderr) wouldn't work either. Not sure if this NPM bug is related. I'm using [email protected] and it looks like they changed where errors get output to.