在不更改工作站的全局 npm 配置或在当前目录中创建 .npmrc
文件的情况下,我想使用私有(private) nexus 注册表运行 npx 包。
那么,是否可以运行 npx
带有内联选项(如registry和strict-ssl)的命令(最好是跨平台)?像这样的东西:
npx somerunnablepackage --registry https://mynexus --strict-ssl false
我在 PowerShell/Windows 上尝试了上面的代码片段,但我的注册表没有被命中,它仍然尝试访问默认注册表 ( https://registry.npmjs.org )。
最佳答案
使用
npm_config_registry=https://mynexus npm_config_strict_ssl=false npx somerunnablepackage
参见https://docs.npmjs.com/cli/v10/using-npm/config#environment-variables
Environment Variables
Any environment variables that start with
npm_config_
will be interpreted as a configuration parameter. For example, puttingnpm_config_foo=bar
in your environment will set thefoo
configuration parameter tobar
. Any environment configurations that are not given a value will be given the value oftrue
. Config values are case-insensitive, soNPM_CONFIG_FOO=bar
will work the same. However, please note that insidescripts
npm will set its own environment variables and Node will prefer those lowercase versions over any uppercase ones that you might set. For details see this issue.Notice that you need to use underscores instead of dashes, so
--allow-same-version
would becomenpm_config_allow_same_version=true
.
关于npx - 运行 npx 时如何传递内联选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59478656/