changesets: SyntaxError: Unexpected end of JSON input when trying to publish packages
Affected Packages
All of the packages
Problem
When I try to publish my packages using pnpx changesets publish
I get this error:
➜ pnpx changeset publish
🦋 info npm info @tinyhttp/app
🦋 info npm info @tinyhttp/cors
🦋 info npm info @tinyhttp/etag
🦋 info npm info @tinyhttp/logger
🦋 info npm info @tinyhttp/static
🦋 info @tinyhttp/app is being published because our local version (0.1.21) has not been published on npm
🦋 info @tinyhttp/cors is being published because our local version (0.1.20) has not been published on npm
🦋 info @tinyhttp/etag is being published because our local version (0.1.20) has not been published on npm
🦋 info @tinyhttp/logger is being published because our local version (0.1.20) has not been published on npm
🦋 info @tinyhttp/static is being published because our local version (0.1.20) has not been published on npm
🦋 info Publishing "@tinyhttp/app" at "0.1.21"
🦋 info Publishing "@tinyhttp/cors" at "0.1.20"
🦋 info Publishing "@tinyhttp/etag" at "0.1.20"
🦋 info Publishing "@tinyhttp/logger" at "0.1.20"
🦋 info Publishing "@tinyhttp/static" at "0.1.20"
🦋 error SyntaxError: Unexpected end of JSON input
🦋 error at JSON.parse (<anonymous>)
🦋 error at internalPublish (/home/v1rtl/Coding/tinyhttp/node_modules/.pnpm/@changesets/cli@2.9.1_@types+node@14.0.13/node_modules/@changesets/cli/dist/cli.cjs.dev.js:591:19)
🦋 error at processTicksAndRejections (internal/process/task_queues.js:97:5)
Same happens with ./node_modules/.bin/changeset publish
I don’t know what causes it because there’s no clear error message.
Helpful info
reproduction repository: https://github.com/talentlessguy/tinyhttp
changesets config: https://github.com/talentlessguy/tinyhttp/blob/master/.changeset/config.json
node
version: 14.4.0
pnpm
version: 5.0.2
npm
version: 6.14.5
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 51 (17 by maintainers)
Commits related to this issue
- build: fix issue in `changesets` with patch https://github.com/atlassian/changesets/issues/397 — committed to remirror/remirror by ifiokjr 4 years ago
- chore: use node version 14 which uses npm 6 which avoids running into https://github.com/atlassian/changesets/issues/397 — committed to n1ru4l/graphql-public-schema-filter by n1ru4l 3 years ago
- add publish config ref: https://github.com/atlassian/changesets/issues/397 — committed to ampcpmgp/toymorphism by ampcpmgp 3 years ago
Yep, already pushed out a change like this a couple of hours ago 😉 :
https://github.com/atlassian/changesets/commit/89a70f9d6702740c8b4c7903faefb8c7286bff20
Need to self-review and retest this before publishing a PR.
Thank you also for other comments - i will take a deeper look into everything you have mentioned
For me, I had to add the following to my package.json’s:
Answer from: https://stackoverflow.com/a/53478078
I had the same issue earlier today and it happened for two reasons.
Reason One
There was a package that was set to
"private": true
in thepackage.json
file. This was unintentional. I attempted to fix this mistake in a recent release by updating thepackage.json
. The problem is that the package already had multipleCHANGELOG.md
entries and as a result, changesets attempts to update the package with aPUT
rather than publish with aPOST
request. Since the package doesn’t actually exist on the registry this causes an error and npm doesn’t respond with json.Fix: Make sure there is only one entry in your changelog file before publishing a package for the first time.
Reason Two
A package I was trying to publish seemed available, but it actually causes an error response from npm when trying to publish. The naming is too similar to another package that already exists. When an error happens the
npm publish
command doesn’t return json and the json cannot be parsed.Fix: Rename the package and retry.
Suggestions
I think the main problem is that changesets assumes that
npm publish
will always return valid json which is not the case. As a result the actual error response is hidden and all we see is an invalid json message.https://github.com/atlassian/changesets/blob/fe8db7500f81caea9064f8bec02bcb77e0fd8fce/packages/cli/src/commands/publish/npm-utils.ts#L180
My suggestion is that thisjsonParse
call should be wrapped in a try catch and when failing it should log the original reponse from npm. This way it will be much easier to identify what the problem is.Updated: Check for
stderr
beforestdout
so errors can be diagnosed more easily.https://github.com/atlassian/changesets/blob/fe8db7500f81caea9064f8bec02bcb77e0fd8fce/packages/cli/src/commands/publish/npm-utils.ts#L169-L175
@rossng where did u get this info from? do u know of any
pnpm
+ other stuff combination that fails to use--json
withpnpm
? i was just testing it and it seems to work.pnpm
simply forwards almost all arguments to thenpm
(and it uses npm’s CLI under the hood for publishing) so in a sense this should “just work”. I’ve tested this manually with pnpm v6 and verified the code for v3, v4, v5, and v6 - they all do roughly the same thing when it comes to this args forwarding tonpm publish
.@abdonrd I’m trying to figure out the proper solution for most of the similar publishing issues to fix this once and for all. Stay tuned
Had this same issue and was able to fix it by downgrading from
npm7
to latestnpm@6
I managed to get the github action to work using this setup.
with this patch
I got this output:
which was a fair sight better than Unexpected end of JSON input.
This is using an NPM “automation token”
I was eventually able to publish by removing the “publishConfig” blocks from my package.jsons
@zkochan I just did my first update using
pnpm publish -r --tag next
and it worked like a charm. Thanks for the tip.I also like how you’re managing releases for the
pnpm
project. I take it you’re using changesets to generate the package specific changelogs and then you’re manually adding your own top level changelog and github release. This strategy makes a lot of sense and I think I’ll adopt it. With 80+ packages in remirror, creating unfiltered package releases has become too noisy.@ifiokjr you may just use pnpm to publish the bumped versions. Just run
pnpm publish -r
.I’m having the exact same issue with
pnpm
The failing build is here https://github.com/remirror/remirror/pull/251/checks?check_run_id=838235175 The commit causing the issue is here: https://github.com/remirror/remirror/tree/7f4153e0b08ae709dbdd28b09d6ebd3809e9a825 Config: https://github.com/remirror/remirror/blob/7f4153e0b08ae709dbdd28b09d6ebd3809e9a825/support/root/.changeset/config.json Prerelease config: https://github.com/remirror/remirror/blob/7f4153e0b08ae709dbdd28b09d6ebd3809e9a825/support/root/.changeset/pre.json
Node
: 12pnpm
: 5.2.6The annoying thing is that I also can’t run the release command from my own machine. It just freezes at the same point with no error displayed.