我已经安装了用于 Windows 的 nvm https://github.com/coreybutler/nvm-windows和 nvm 列表显示
17.2.0
* 16.13.1 (Currently using 64-bit executable)
14.5.0
10.21.0
8.12.0
如果我跑npx -v
I get 8.1.2
但如果我跑说npx create-next-app@latest --ts
然后我得到
Need to install the following packages:
create-next-app@latest
Ok to proceed? (y)
如果我切换到 14.5.0 说nvm use 14.5.0
然后运行npx -v
I get 6.14.0
如果我然后跑说npx create-next-app@latest --ts
然后我得到的预期输出
npx: installed 1 in 1.772s
? What is your project named? » my-app
对于 nvm use 17.2.0,其行为与 nvm use 16.13.1 类似。并在 17.2.0 中运行npx -v
输出8.1.4
对于 nvm 使用 10.21.0 和 8.12.0,npx 按预期工作,而不要求我全局下载 create-next-app,就像使用高于 14.5.0 的节点版本一样。
14.5.0 及更低版本的另一件事,如果我这样做的话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).
但对于 16.13.1 及更高版本来说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] [--include-workspace-root]
alias: x
Run "npm help exec" for more info
我假设 npx 与 npm 一起“预安装”,因此切换到任何高于 5.2.0 的 npm 版本应该使 npx 可用。
我当然可以简单地nvm use 14.5.0
继续我的生意,但很好奇为什么 npx 在 16.3.1 和 17.2.0 上表现不佳。除非我没有做错什么事情。