How to fix npm ERR! code EUSAGE npm ERR! npx: cannot use --yes and --no together in npm
The EUSAGE error occurs when you pass both --yes and --no flags to npx, which are mutually exclusive. Use only one flag: --yes to install without prompting, or --no to use only locally installed packages.
Quick fix
Fixes EUSAGE
# Install packages without prompting
npx --yes create-react-app my-app
# Use only locally installed packages
npx --no eslint .- Choose one flag
- Understand when to use each flag
- Check for environment variable conflicts
- Fix build scripts
# Install packages without promptingnpx --yes create-react-app my-app# Use only locally installed packagesnpx --no eslint .npm ERR! code EUSAGEnpm ERR! npx: cannot use --yes and --no together
What this error means
This error occurs when you pass both --yes (-y) and --no flags to npx. These flags are mutually exclusive because they represent opposite behaviors: - `--yes`: Automatically install and run packages without prompting - `--no`: Only use locally installed packages, never download from registry Using both simultaneously is contradictory, so npx rejects the command. This often happens in build scripts where flags are concatenated from multiple sources or environment variables.
Typical symptoms
- npx command fails immediately with EUSAGE error
- Error message: 'cannot use --yes and --no together'
- Build scripts fail silently or hang
- CI/CD pipeline fails on npx commands
- Works in some environments but not others
Common causes
- Explicitly passing both --yes and --no flags
- Script concatenating multiple flag variables
- Environment variable conflict (npm_config_yes + explicit --no)
- Copy-paste error from documentation
- Template or scaffold generating conflicting flags
How to fix "npm ERR! code EUSAGE npm ERR! npx: cannot use --yes and --no together"
Use either --yes or --no, not both:
# Install packages without prompting
npx --yes create-react-app my-app
# Use only locally installed packages
npx --no eslint .The flags are mutually exclusive by design.
Use --yes when:
- Running in CI/CD (no user to answer prompts)
- You want to always use the latest version
- First-time setup scripts
Use --no when:
- You want reproducible builds with local versions only
- Security-conscious environments
- Offline development
npm config can set --yes globally:
# Check if yes is set
npm config get yes
# Unset if needed
npm config delete yesOr check environment:
echo $npm_config_yesReview scripts that construct npx commands:
# Bad: concatenating flags that might conflict
NPX_FLAGS="--yes"
NPX_FLAGS="$NPX_FLAGS --no" # Oops!
npx $NPX_FLAGS create-app
# Good: use conditional logic
if [ "$CI" = "true" ]; then
npx --yes create-app
else
npx create-app
fiFor cross-version compatibility (npm 6 through 10+):
npm_config_yes=true npx create-react-app my-appThis works in CI environments and is ignored by npm versions that don't support --yes.
Advanced notes
The --yes flag was introduced in npm 7. In npm 6, npx would always prompt or auto-install depending on context.
For CI/CD environments, the recommended patterns are:
GitHub Actions:
- run: npx --yes create-react-app my-appDocker:
RUN npm_config_yes=true npx create-react-app my-appIf you need to support both npm 6 and npm 7+, use the environment variable approach since --yes doesn't exist in npm 6.
The --no flag (or --no-install) is useful for ensuring you only run locally installed versions, which is important for security and reproducibility. However, it will fail if the package isn't already installed locally.
Frequently asked questions
- What does "EUSAGE" mean?
- This error occurs when you pass both --yes (-y) and --no flags to npx. These flags are mutually exclusive because they represent opposite behaviors: - --yes: Automatically install and run packages without prompting - --no: Only use locally installed packages, never download from registry Using both simultaneously is contradictory, so npx rejects the command. This often happens in build scripts where flags are concatenated from multiple sources or environment variables.
- How do I fix "EUSAGE"?
- The EUSAGE error occurs when you pass both --yes and --no flags to npx, which are mutually exclusive. Use only one flag: --yes to install without prompting, or --no to use only locally installed packages.
- What causes "EUSAGE"?
- Explicitly passing both --yes and --no flags Script concatenating multiple flag variables Environment variable conflict (npm_config_yes + explicit --no)
- Is the "EUSAGE" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐
- ๐GitHub #2226: npm/cli(GitHub)
- ๐ฌ