Skip to content
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

Can't determine real reason behind fail of nx release publish due to inaccurate error handling #22210

Closed
1 of 4 tasks
tabomors opened this issue Mar 7, 2024 · 8 comments
Closed
1 of 4 tasks

Comments

@tabomors
Copy link

tabomors commented Mar 7, 2024

Current Behavior

Currently on Gitlab CI we try are tryng to run nx release publish but it fails with error Cannot read properties of undefined (reading 'summary') on this line https://github.com/nrwl/nx/blob/master/packages/js/src/executors/release-publish/release-publish.impl.ts#L240. This log hides the true cause of the error. It happens because this line https://github.com/nrwl/nx/blob/master/packages/js/src/executors/release-publish/release-publish.impl.ts#L237C7-L237C69 actually an empty object then it tries to get error.summary from it and fails

Expected Behavior

If there is no stdoutData.error I would expect to see original error:

const stdoutData = JSON.parse(err.stdout?.toString() || '{}');

console.error('npm publish error:');
if (err.stdout) {
  if (stdoutData.error.summary) {
    console.error(stdoutData.error.summary);
  }
  if (stdoutData.error.detail) {
    console.error(stdoutData.error.detail);
  }
} else {
  console.error(err);
}

GitHub Repo

No response

Steps to Reproduce

Unfortunately I am not sure why this code goes to this point and how to provide steps to reproduce. I hope if error handling would be improved I can get back to this thread with more information

Nx Report

Node   : 18.12.0
OS     : linux-x64
npm    : 8.19.4
nx                 : 18.0.7
@nx/js             : 18.0.7
@nx/jest           : 18.0.7
@nx/linter         : 18.0.7
@nx/eslint         : 18.0.7
@nx/workspace      : 18.0.7
@nx/devkit         : 18.0.7
@nx/esbuild        : 18.0.7
@nx/eslint-plugin  : 18.0.7
@nx/nest           : 18.0.7
@nx/node           : 18.0.7
@nx/plugin         : 18.0.7
@nrwl/tao          : 18.0.7
@nx/webpack        : 18.0.7
typescript         : 5.3.3

Failure Logs

npm WARN config `_auth`, `_authToken`, `username` and `_password` must be scoped to a registry. see `npm help npmrc` for more information.
npm WARN config `_auth`, `_authToken`, `username` and `_password` must be scoped to a registry. see `npm help npmrc` for more information.
npm publish error:
Something unexpected went wrong when processing the npm publish output
 TypeError: Cannot read properties of undefined (reading 'summary')
    at runExecutor (/builds/ifi/frontend/core/.cache/modules-18/node_modules/@nx/js/src/executors/release-publish/release-publish.impl.js:176:34)
    at runExecutorInternal (/builds/ifi/frontend/core/.cache/modules-18/node_modules/nx/src/command-line/run/run.js:88:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /builds/ifi/frontend/core/.cache/modules-18/node_modules/nx/src/command-line/run/run.js:169:44
    at async handleErrors (/builds/ifi/frontend/core/.cache/modules-18/node_modules/nx/src/utils/params.js:9:16)
    at async process.<anonymous> (/builds/ifi/frontend/core/.cache/modules-18/node_modules/nx/bin/run-executor.js:59:28)

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@dkhrunov
Copy link

Same problem

  • GitLab CI
  • nx@17.0.3
  • angular@~14.2.0

@adambiggs
Copy link

Also experiencing this

  • GitHub Actions
  • nx@18.1.3
  • yarn@4.1.1

@tabomors
Copy link
Author

tabomors commented Apr 16, 2024

For me updating of nx to the latest version helped, so I don't have errors during publish but still I guess it would be helpful to show users the real reason of failure if there are any

@adambiggs
Copy link

Digging a bit further, in my case the error was caused by one of our packages having a prepack lifecycle script that ran yarn build.

This adds the following lines to the command output, causing JSON parsing to fail:

> my-package-name prepack
> yarn build

Aside from surfacing this error, what's the recommended way to use the prepack hook with nx release?

@adambiggs
Copy link

Looks like this change in npm@10.5.0 is the root cause of my issue.

Adding --foreground-scripts false to the npm publish command should fix the issue.

@maratsh
Copy link

maratsh commented May 16, 2024

I have the same issue. whenver npm fails, I get

  npm publish error:
  Something unexpected went wrong when processing the npm publish output
   TypeError: Cannot read properties of undefined (reading 'summary')

@JamesHenry
Copy link
Collaborator

Hi Folks, sorry for the delay in acknowledging this one, it was actually addressed a while ao by #23850, please update to the latest Nx and you shouldn't see the same behaviour.

Please open a fresh issue with minimal steps to reproduce if you encounter any further issues.

Many thanks!

Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants