New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SyntaxError: Unexpected end of JSON input when trying to publish packages #397
Comments
I'm having the exact same issue with The failing build is here https://github.com/remirror/remirror/pull/251/checks?check_run_id=838235175
The 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. |
Thank you both for those reports. I will make sure to investigate this asap. |
In order to get the release to work I've patched the It's possible something changed in |
@ifiokjr you may just use pnpm to publish the bumped versions. Just run |
Ahh that's very useful to know. It looks like |
@zkochan I just did my first update using I also like how you're managing releases for the |
@zkochan i think I've already asked this in the past, but... do you see any difference between our publishing script and I would still be interested in investigating why this fails though:https://github.com/atlassian/changesets/blob/81595022e27e4b94a1bc87e56eabafb9a31e8315/packages/cli/src/commands/publish/npm-utils.ts#L126-L138 |
We've just released a new version of |
@Andarist hello, I tried it once again, here's the output:
|
Figured out the bug @Andarist @zkochan: there's a race condition between I think, basically, |
In case that appears to be a non-sequitor, the error actually comes from the manifest being published referencing another dependency in the monorepo, whose manifest is currently missing as it undergoes the pnpm transition. |
@devin-fee-ah how this can result in a JSON.parse fail later? π€ I understand that the manifest can not be updated properly but it seems like a potentially different problem.
This is probably the way to go for multiple reasons. Would you be willing to help us with this one? I probably won't have time to work on this one any time soon. |
Adding additional logging to // extra
console.error(stdout.toString())
console.error(stderr.toString())
// original: ~L701 in function internalPublish
let json = jsonParse(stdout.toString().replace(/[^{]*/, "")); I get:
That error is the one i'd mentioned above btw, Now, for a different problem, I'm only getting pnpm to publish ~75% of my packages using |
Is this caused by the mentioned problem or is it a different problem with Changesets or Pnpm itself? |
That last part is independent of changesets. |
Gotcha, thank you for investigating this and providing more information. This is very helpful. I think at this point it's pretty obvious what we should do but there are no time resources in the team to handle this ourselves. I can provide guidance, reviews etc for anyone who would like to help out though. |
Alterrnatively, you could provide a third entrypoint ββ "tag". So we'd have [ The niceness of having |
Could u prepare a separate issue for the |
Done. #478 |
I've been having a similar problem with one of my packages (not a monorepo). Here's an example of failed run: https://github.com/wikibus/Alcaeus/runs/1589751903?check_suite_focus=true Is this the same problem? How do I resolve it? |
Thanks for the report and link to the failed run - I will try to look into it but I have a lot on my plate right now so it might take a while. If you could investigate this further it could help us tremendously |
@tpluscode it seems like literally My bet is that this is actually caused by the fact that your project depends on gitbook which in turn depends (maybe indirectly) on some very old version of npm and this To fix this we'd have to figure out how to call the correct version of |
Ah thank you for investigating. I have in fact started removing gitbook from the picture so I should good once its gone :) |
We were just bit by this on our last publish (curiously our first publish went fine, but once we published more packages it triggered whatever causes this)
For more context we publish to a private Jfrog Artifactory server instead of canonical NPM |
It's really hard for us to repro this - given this occurs in very specific setups etc. Could you try to debug this? I would try rechecking what exact |
Running into the same issue here when executing
However, executing |
Same here, I'd say |
I think that the best way to move forward would be to handle publish using the APIs rather than CLI. This would allow us for more fine-grained control over the input arguments and the result. I'm afraid that I don't have time to work on that right now - but I would be happy to review a PR implementing this. |
Got the same error. Turned out the call to
|
I also just ran into this using the changesets github action.
This is a very small test repo for me to evaluate changesets in a publish setting (proof of concept) so i'm happy to send my code over if it will help. I'm using the following: node: |
(https://github.com/atlassian/changesets/blob/main/docs/command-line-options.md#git-tags) |
with this patch diff --git a/node_modules/@changesets/cli/dist/cli.cjs.dev.js b/node_modules/@changesets/cli/dist/cli.cjs.dev.js
index f771824..1577813 100644
--- a/node_modules/@changesets/cli/dist/cli.cjs.dev.js
+++ b/node_modules/@changesets/cli/dist/cli.cjs.dev.js
@@ -727,7 +727,8 @@ async function internalPublish(pkgName, opts, twoFactorState) {
npm_config_registry: getCorrectRegistry()
};
let {
- stdout
+ stdout,
+ stderr,
} = await spawn__default['default'](publishTool.name, ["publish", opts.cwd, "--json", ...publishFlags], {
env: Object.assign({}, process.env, envOverride)
}); // New error handling. NPM's --json option is included alongside the `prepublish and
@@ -735,7 +736,7 @@ async function internalPublish(pkgName, opts, twoFactorState) {
// some struggles
// Note that both pre and post publish hooks are printed before the json out, so this works.
- let json = jsonParse(stdout.toString().replace(/[^{]*/, ""));
+ let json = jsonParse(stdout.toString().replace(/[^{]*/, "") || stderr.toString().replace(/^npm ERR.*$/gm, '').replace(/[^{]*/, ""));
if (json.error) {
// The first case is no 2fa provided, the second is when the 2fa is wrong (timeout or wrong words) 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 |
For anyone struggling out here: I also tried setting up changesets for a single package repository and had the same issue as OP. I also use the publishConfig option in my package.json: {
"publishConfig": {
"access": "public",
"directory": "dist"
}
} First I tried reverting from Node.js 16 to 14 (as 14 uses npm 6 instead of npm 7). Doing so resulted in a more detailed error message: π¦ error an error occurred while publishing @n1ru4l/graphql-public-schema-filter: ENOPACKAGEJSON ENOENT: no such file or directory, open '/home/runner/work/graphql-public-schema-filter/graphql-public-schema-filter/dist/package.json'
π¦ error npm can't find a package.json file in your current directory.
π¦ error packages failed to publish:
π¦ @n1ru4l/graphql-public-schema-filter@0.2.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: The process '/usr/local/bin/yarn' failed with exit code 1
Error: The process '/usr/local/bin/yarn' failed with exit code 1
at a._setResult (/home/runner/work/_actions/changesets/action/master/dist/index.js:86:6638)
at a.CheckComplete (/home/runner/work/_actions/changesets/action/master/dist/index.js:86:6068)
at ChildProcess.<anonymous> (/home/runner/work/_actions/changesets/action/master/dist/index.js:86:5102)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) Which made me realize I forgot to run my build script π . SO I reverted back to Node.js 16 and simply added the build step. See these two commits: n1ru4l/graphql-public-schema-filter@c3677b1 |
I'm still getting this issue with npm7, any new insights?
|
The documentation recommends setting |
@bennypowers As we already discussed and found out, you actually have to set both Β―_(γ)_/Β― |
I'm also seeing this. Seems like
Then the json parser breaks because the command is empty.
The package.json for package-d is correct... Has anyone found a fix for this issue? |
For me, I had to add the following to my package.json's:
Answer from: https://stackoverflow.com/a/53478078 |
I also ran into this issue when trying to publish my pnpm monorepo with changesets. There seem to be at least two issues here:
On the first issue, I don't think there's much that can be done until NPM fixes the glaring regression. I wouldn't mind trying to patch the second issue. I think the best thing would be to special-case pnpm - i.e. listen for the exit code of the pnpm process and, upon failure, pack the entire |
There are news? Now I have the same error... https://github.com/qiskit-community/qiskit-web-components/runs/4026323508?check_suite_focus=true |
@rossng where did u get this info from? do u know of any
@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 |
@Andarist I think you are right in the case of publishing. I had noticed that pnpm didn't support Glad to hear you are working on this - happy to help/test if needed. |
I had the same issue earlier today and it happened for two reasons. Reason OneThere was a package that was set to Fix: Make sure there is only one entry in your changelog file before publishing a package for the first time. Reason TwoA 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 Fix: Rename the package and retry. SuggestionsI think the main problem is that changesets assumes that
Updated: Check for |
@Andarist would it help to first check for |
Yep, already pushed out a change like this a couple of hours ago π : 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 |
I've created a pull request that attempts to fix the issues mentioned here. I will setup snapshot releases for this PR soon-ish but in the meantime I would love to ask if there are any people willing to test this stuff out in their projects. |
Does anyone have solutions for this lol |
I managed to get the github action to work using this setup. name: Release
on:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
NPM_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'
token: ${{ secrets.GH_RELEASE_TOKEN }}
registry-url: 'https://npm.pkg.github.com'
- name: Install Dependencies
run: npm ci
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: npm run release |
Affected Packages
All of the packages
Problem
When I try to publish my packages using
pnpx changesets publish
I get this error: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.0pnpm
version: 5.0.2npm
version: 6.14.5The text was updated successfully, but these errors were encountered: