2

Synopsis

When I use npx create-next-app@latest, I am prompted to install a newer package version. I cannot find a parameter on npx to make the command silently work inside of a script.

For example, I would expect to find a parameter such as --silent or --force or --yes, as is common convention with other package managers.

There has to be an easy answer to this, but I honestly can't find it.

FYI I am using PowerShell as my shell environment on Windows 10, although I would expect the npx command to provide a parameter, instead of having to use shell features (piping) to accomplish this.

PS C:\git\myapp> npx create-next-app@latest
Need to install the following packages:
  create-next-app@latest
Ok to proceed? (y)

The npx --help command doesn't produce any guidance.

PS > npx --help
npm exec

Run a command from a local or remote npm package

Usage:
npm exec -- <pkg>[@<version>] [args...]
npm exec --package=<pkg>[@<version>] -- <cmd> [args...]
npm exec -c '<cmd> [args...]'
npm exec --package=foo -c '<cmd> [args...]'

Options:
[--package <pkg>[@<version>] [--package <pkg>[@<version>] ...]]
[-c|--call <call>]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]

alias: x

Run "npm help exec" for more info

Actual Result

npx pauses execution until user input is provided.

Expected Result

npx automatically installs the latest version of the package and executes it, without prompting the user.

  • Would [this answer](https://stackoverflow.com/questions/14071012/how-do-i-automatically-answer-yes-to-a-prompt-in-powershell) apply here? – Phix Jul 26 '21 at 17:03
  • @Phix Nope that covers a different use case. –  Jul 26 '21 at 17:03

2 Answers2

1

This appears to be a bug. According to the online documentation, the --yes parameter is supported on npm exec (aka. npx). However, on version 7.19.1 of npm, specifying the --yes option is ignored by the CLI.

To reproduce the problem, run a new Node.js container using the Docker CLI, using a Bash shell:

docker run --rm --interactive --tty node:16.5.0 bash

Then, run these commands inside the container:

npm install --global create-next-app@10.0.9
npx create-next-app@latest --yes

Here's the version information from the 16.5.0 container image:

{
  npm: '7.19.1',
  node: '16.5.0',
  v8: '9.1.269.38-node.20',
  uv: '1.41.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.17.1',
  modules: '93',
  nghttp2: '1.42.0',
  napi: '8',
  llhttp: '6.0.2',
  openssl: '1.1.1k+quic',
  cldr: '39.0',
  icu: '69.1',
  tz: '2021a',
  unicode: '13.0',
  ngtcp2: '0.1.0-DEV',
  nghttp3: '0.1.0-DEV'
}
1

I had a similar issue with npx, —-yes was not working but -y worked for me.

Cyrux
  • 11
  • 2