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

fix: much clearer npx 'canceled' error #6642

Merged
merged 5 commits into from
Jul 17, 2023

Conversation

rahulio96
Copy link
Contributor

Summary

Currently, when running npx --no-install on a package that is not installed will return a vague error message that says, “canceled.”

Added accompanying tap test to ensure the expected error is outputted.

This solution gives the error message more clarity to make debugging easier.

image

Testing

Reproduce Original Error:

  • Enter in terminal:
    • npx --no-install <missing_package>
      Please Note: <missing_package> is either not installed or in path

Tap Test (exec.js only)

  • Enter in terminal:
    • node . run test test/lib/commands/exec.js

Run entire test:

  • Enter in terminal:
    • node . run test

Alias Test

  • Enter in terminal:
    • alias localnpx="node /workspaces/cli/bin/npx-cli.js"
    • localnpx --no-install esbuild

References

Fixes #6215

@rahulio96 rahulio96 requested a review from a team as a code owner July 13, 2023 21:55
@wraithgar wraithgar self-assigned this Jul 17, 2023
// set -n to always say no
if (yes === false) {
throw new Error('canceled')
// Error message lists missing package(s) when process is canceled
throw new Error(`npx canceled due to missing packages and no YES option: ${JSON.stringify(missingPackages)}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error(`npx canceled due to missing packages and no YES option: ${JSON.stringify(missingPackages)}`)
/* eslint-disable-next-line max-len */
throw new Error(`npx canceled due to missing packages and no YES option: ${JSON.stringify(missingPackages)}`)

@wraithgar
Copy link
Member

Can you please add the max-len override for the thrown error, then run npm run lintfix -w libnpmexec --include-workspace-root

@AaronHamilton965
Copy link
Contributor

Thanks for the feedback, we made the appropriate changes that you suggested!

@wraithgar wraithgar changed the title fix: npx 'canceled' error reason lacks clarity fix: much clearer npx 'canceled' error Jul 17, 2023
Copy link
Member

@wraithgar wraithgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@wraithgar wraithgar merged commit 02c7ddb into npm:latest Jul 17, 2023
@github-actions github-actions bot mentioned this pull request Jul 17, 2023
@DevBrent
Copy link

DevBrent commented Mar 13, 2024

What does "no YES option" mean? How can you correct this if you encounter this error? What is the option you need to add?

@rahulio96
Copy link
Contributor Author

The “no YES option” is what --no-install is doing. It means that npx will not install any missing packages and will try to run the command as is. If you are getting the npx canceled due to missing packages and no YES option error, it means you are missing the required packages/dependencies for the command to run properly.

If you want your command to execute, instead of using --no-install try using install instead. If that does not work, try installing the missing packages mentioned in the error message using npm install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] npx 'canceled' error reason lacks clarity
4 participants