npx on windows 10 with nvm causes need to install following packages

Viewed 1027

I've installed nvm for windows and nvm list shows

    17.2.0
  * 16.13.1 (Currently using 64-bit executable)
    14.5.0
    10.21.0
    8.12.0

If I run npx -v I get 8.1.2 but if I run say npx create-next-app@latest --ts then I get

Need to install the following packages:
  create-next-app@latest
Ok to proceed? (y)

If I switch to 14.5.0 by saying nvm use 14.5.0 and then run npx -v I get 6.14.0 & if I then run say npx create-next-app@latest --ts then I get the expected output of

npx: installed 1 in 1.772s
? What is your project named? » my-app

With nvm use 17.2.0, behaves similar to nvm use 16.13.1. and with 17.2.0, running npx -v outputs 8.1.4

For nvm use 10.21.0 and 8.12.0, npx works as expected without asking me to download create-next-app globally as it does with node versions higher than 14.5.0.

One other thing with 14.5.0 and lower, if I do npx --help I get

Execute binaries from npm packages.

  npx [options] <command>[@version] [command-arg]...

  npx [options] [-p|--package <package>]... <command> [command-arg]...

  npx [options] -c '<command-string>'

  npx --shell-auto-fallback [shell]


Options:
  --package, -p          Package to be installed.                       [string]
  --cache                Location of the npm cache.                     [string]
  --always-spawn         Always spawn a child process to execute the command.
                                                                       [boolean]
  --no-install           Skip installation if a package is missing.    [boolean]
  --userconfig           Path to user npmrc.                            [string]
  --call, -c             Execute string as if inside `npm run-script`.  [string]
  --shell, -s            Shell to execute the command with, if any.
                                                       [string] [default: false]
  --shell-auto-fallback  Generate shell code to use npx as the "command not
                         found" fallback.
                                   [string] [choices: "", "bash", "fish", "zsh"]
  --ignore-existing      Ignores existing binaries in $PATH, or in the local
                         project. This forces npx to do a temporary install and
                         use the latest version.                       [boolean]
  --quiet, -q            Suppress output from npx itself. Subcommands will not
                         be affected.                                  [boolean]
  --npm                  npm binary to use for internal operations.
                                                              [string] [default:
  "C:\Users\Sangeet\AppData\Roaming\nvm\v14.5.0\node_modules\npm\bin\npm-cli.js"
                                                                               ]
  --node-arg, -n         Extra node argument when calling a node binary.[string]
  --version, -v          Show version number                           [boolean]
  --help, -h             Show help                                     [boolean]

For the full documentation, see the manual page for npx(1).

But with 16.13.1 and higher saying npx --help gives me

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] [--include-workspace-root]

alias: x

Run "npm help exec" for more info

I'm assuming npx comes "pre-installed" with npm so switching to any npm version higher that 5.2.0 should make npx available.

I can of course simply nvm use 14.5.0 & go about my business but was very curious why npx is not behaving itself for 16.3.1 and 17.2.0. Unless I'm not doing some thing incorrectly.

1 Answers

Apparently this is the new way npx behaves per github issue

Seems @jcollum ran across the very same issue per this stackoverflow question.

Related