config

关于 npm 配置,你可能想知道的更多

选择命令行版本:

目录

描述

🌐 Description

npm 从以下来源获取其配置值,按优先级排序:

🌐 npm gets its configuration values from the following sources, sorted by priority:

命令行标志

🌐 Command Line Flags

在命令行上使用 --foo bar 会将 foo 配置参数设置为 "bar"-- 参数告诉命令行解析器停止读取标志。使用 --flag 而不指定任何值将把值设置为 true

🌐 Putting --foo bar on the command line sets the foo configuration parameter to "bar". A -- argument tells the cli parser to stop reading flags. Using --flag without specifying any value will set the value to true.

示例:--flag1 --flag2 将两个配置参数都设置为 true,而 --flag1 --flag2 barflag1 设置为 true,并将 flag2 设置为 bar。最后,--flag1 --flag2 -- bar 将两个配置参数都设置为 truebar 被作为命令参数使用。

🌐 Example: --flag1 --flag2 will set both configuration parameters to true, while --flag1 --flag2 bar will set flag1 to true, and flag2 to bar. Finally, --flag1 --flag2 -- bar will set both configuration parameters to true, and the bar is taken as a command argument.

环境变量

🌐 Environment Variables

任何以 npm_config_ 开头的环境变量都会被解释为配置参数。例如,在你的环境中放置 npm_config_foo=bar 会将 foo 配置参数设置为 bar。任何未赋值的环境配置将会被赋值为 true。配置值不区分大小写,因此 NPM_CONFIG_FOO=bar 的效果是一样的。然而,请注意,在 scripts 中,npm 会设置它自己的环境变量,并且 Node 会优先使用这些小写版本,而不是你可能设置的任何大写版本。详情请参阅 此问题

🌐 Any environment variables that start with npm_config_ will be interpreted as a configuration parameter. For example, putting npm_config_foo=bar in your environment will set the foo configuration parameter to bar. Any environment configurations that are not given a value will be given the value of true. Config values are case-insensitive, so NPM_CONFIG_FOO=bar will work the same. However, please note that inside scripts 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.

请注意,你需要使用下划线而不是破折号,因此 --allow-same-version 将变为 npm_config_allow_same_version=true

🌐 Notice that you need to use underscores instead of dashes, so --allow-same-version would become npm_config_allow_same_version=true.

npmrc 文件

🌐 npmrc Files

四个相关文件是:

🌐 The four relevant files are:

  • 每项目配置文件(/path/to/my/project/.npmrc
  • 每用户配置文件(默认值为 $HOME/.npmrc;可通过命令行选项 --userconfig 或环境变量 $NPM_CONFIG_USERCONFIG 配置)
  • 全局配置文件(默认为 $PREFIX/etc/npmrc;可通过 CLI 选项 --globalconfig 或环境变量 $NPM_CONFIG_GLOBALCONFIG 配置)
  • npm 内置的配置文件(/path/to/npm/npmrc

有关更多详细信息,请参见 npmrc

🌐 See npmrc for more details.

默认配置

🌐 Default Configs

运行 npm config ls -l 可以查看一组 npm 的内部配置参数,如果没有指定其他内容,这些参数将作为默认值。

🌐 Run npm config ls -l to see a set of configuration parameters that are internal to npm, and are defaults if nothing else is specified.

速记和其他 CLI 细节

🌐 Shorthands and Other CLI Niceties

在命令行上解析以下简写:

🌐 The following shorthands are parsed on the command-line:

  • -a--all
  • --enjoy-by--before
  • -c--call
  • --desc--description
  • -f--force
  • -g--global
  • --iwr--include-workspace-root
  • -L--location
  • -d--loglevel info
  • -s--loglevel silent
  • --silent--loglevel silent
  • --ddd--loglevel silly
  • --dd--loglevel verbose
  • --verbose--loglevel verbose
  • -q--loglevel warn
  • --quiet--loglevel warn
  • -l--long
  • -m--message
  • --local--no-global
  • -n--no-yes
  • --no--no-yes
  • -p--parseable
  • --porcelain--parseable
  • -C--prefix
  • --readonly--read-only
  • --reg--registry
  • -S--save
  • -B--save-bundle
  • -D--save-dev
  • -E--save-exact
  • -O--save-optional
  • -P--save-prod
  • -?--usage
  • -h--usage
  • -H--usage
  • --help--usage
  • -v--version
  • -w--workspace
  • --ws--workspaces
  • -y--yes

如果指定的配置参数可以明确解析为已知的配置参数,则它将被扩展为该配置参数。例如:

🌐 If the specified configuration param resolves unambiguously to a known configuration parameter, then it is expanded to that configuration parameter. For example:

npm ls --par
# same as:
npm ls --parseable

如果多个单字符缩写连接在一起,并且结果组合明确不是其他配置参数,那么它会被展开为其各个组成部分。例如:

🌐 If multiple single-character shorthands are strung together, and the resulting combination is unambiguously not some other configuration param, then it is expanded to its various component pieces. For example:

npm ls -gpld
# same as:
npm ls --global --parseable --long --loglevel info

配置设置

🌐 Config Settings

_auth

  • 默认值:空
  • 类型:空或字符串

在对 npm 注册表进行身份验证时使用的基本认证字符串。这将仅用于对 npm 注册表进行身份验证。对于其他注册表,你需要像“//other-registry.tld/:_auth”这样指定作用域

🌐 A basic-auth string to use when authenticating against the npm registry. This will ONLY be used to authenticate against the npm registry. For other registries you will need to scope it like "//other-registry.tld/:_auth"

警告:通常不应通过命令行选项设置此项。更安全的做法是通过运行 npm login 将注册表提供的身份验证令牌存储在 ~/.npmrc 文件中。

🌐 Warning: This should generally not be set via a command-line option. It is safer to use a registry-provided authentication bearer token stored in the ~/.npmrc file by running npm login.

access

  • 默认:新包为 'public',现有包不会改变当前级别
  • 类型:null、“restricted”或“public”

如果你不希望你的作用域包被公开查看(和安装),请设置 --access=restricted

🌐 If you do not want your scoped package to be publicly viewable (and installable) set --access=restricted.

未加作用域的包不能设置为 restricted

🌐 Unscoped packages can not be set to restricted.

注意:默认情况下,这不会更改现有包的当前访问级别。在发布时指定 restrictedpublic 的值将像 npm access set status 一样更改现有包的访问权限。

🌐 Note: This defaults to not changing the current access level for existing packages. Specifying a value of restricted or public during publish will change the access for an existing package the same way that npm access set status would.

all

  • 默认:否
  • 类型:布尔

在运行 npm outdatednpm ls 时,设置 --all 将显示所有过时或已安装的软件包,而不仅仅是当前项目直接依赖的那些包。

🌐 When running npm outdated and npm ls, setting --all will show all outdated or installed packages, rather than only those directly depended upon by the current project.

allow-same-version

  • 默认:否
  • 类型:布尔

当使用 npm version 将新版本设置为与当前版本相同的值时,可防止抛出错误。

🌐 Prevents throwing an error when npm version is used to set the new version to the same value as the current version.

audit

  • 默认:是
  • 类型:布尔

当设置为“true”时,会将审核报告与当前的 npm 命令一起提交到默认注册表以及为作用域配置的所有注册表。有关提交内容的详细信息,请参阅 npm audit 文档。

🌐 When "true" submit audit reports alongside the current npm command to the default registry and all registries configured for scopes. See the documentation for npm audit for details on what is submitted.

audit-level

  • 默认值:空
  • 类型:null、“信息”、“低”、“中等”、“高”、“严重”或“无”

npm audit 以非零退出代码退出的最低漏洞级别。

🌐 The minimum level of vulnerability for npm audit to exit with a non-zero exit code.

auth-type

  • 默认: "网页"
  • 类型:"legacy" 或 "web"

使用 login 时应使用什么认证策略。请注意,如果提供了 otp 配置,此值将始终设置为 legacy

🌐 What authentication strategy to use with login. Note that if an otp config is given, this value will always be set to legacy.

before

  • 默认值:空
  • 类型:空或日期

如果传递给 npm install,将重新构建 npm 树,使得仅安装在 --before 时间之前或当时可用的版本。如果当前的直接依赖集合没有可用的版本,命令将报错。

🌐 If passed to npm install, will rebuild the npm tree such that only versions that were available on or before the --before time get installed. If there's no versions available for the current set of direct dependencies, the command will error.

如果请求的版本是 dist-tag,且给定的标签未通过 --before 过滤器,则将使用小于或等于该标签的最新版本。例如,foo@latest 可能会安装 foo@1.2,即使 latest2.0

🌐 If the requested version is a dist-tag and the given tag does not pass the --before filter, the most recent version less than or equal to that tag will be used. For example, foo@latest might install foo@1.2 even though latest is 2.0.

  • 默认:是
  • 类型:布尔

告诉 npm 为包的可执行文件创建符号链接(在 Windows 上则创建 .cmd 垫片)。

🌐 Tells npm to create symlinks (or .cmd shims on Windows) for package executables.

设置为 false 可使其不执行此操作。这可以用来应对某些文件系统不支持符号链接的情况,即使在表面上的 Unix 系统上也是如此。

🌐 Set to false to have it not do this. This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems.

browser

  • 默认:OS X:"open",Windows:"start",其他:"xdg-open"
  • 类型:null、布尔值或字符串

npm 命令调用以打开网站的浏览器。

🌐 The browser that is called by npm commands to open websites.

设置为 false 以抑制浏览器行为,而改为将 URL 打印到终端。

🌐 Set to false to suppress browser behavior and instead print urls to terminal.

设置为 true 以使用默认系统 URL 打开程序。

🌐 Set to true to use default system URL opener.

ca

  • 默认值:空
  • 类型:null 或字符串(可以多次设置)

用于 SSL 连接注册表的受信任证书颁发机构签名证书。值应为 PEM 格式(Windows 称之为“Base-64 编码 X.509 (.CER)”),其中换行符替换为字符串“\n”。例如:

🌐 The Certificate Authority signing certificate that is trusted for SSL connections to the registry. Values should be in PEM format (Windows calls it "Base-64 encoded X.509 (.CER)") with newlines replaced by the string "\n". For example:

ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

设置为 null 以仅允许“已知”的注册机构,或设置为特定的 CA 证书以仅信任该特定的签署机构。

🌐 Set to null to only allow "known" registrars, or to a specific CA cert to trust only that specific signing authority.

通过指定证书数组可以信任多个 CA:

🌐 Multiple CAs can be trusted by specifying an array of certificates:

ca[]="..."
ca[]="..."

另请参阅 strict-ssl 配置。

🌐 See also the strict-ssl config.

cache

  • 默认值:Windows: %LocalAppData%\npm-cache,Posix: ~/.npm
  • 类型:路径

npm 的缓存目录的位置。

🌐 The location of npm's cache directory.

cafile

  • 默认值:空
  • 类型:路径

指向包含一个或多个证书授权机构签名证书的文件的路径。类似于 ca 设置,但允许使用多个 CA,并且可以将 CA 信息存储在磁盘上的文件中。

🌐 A path to a file containing one or multiple Certificate Authority signing certificates. Similar to the ca setting, but allows for multiple CA's, as well as for the CA information to be stored in a file on disk.

call

  • 默认值:
  • 类型:字符串

npm execnpx 的可选伴随选项,允许指定一个自定义命令与已安装的软件包一起运行。

🌐 Optional companion option for npm exec, npx that allows for specifying a custom command to be run along with the installed packages.

npm exec --package yo --package generator-node --call "yo node"

cidr

  • 默认值:空
  • 类型:null 或字符串(可以多次设置)

这是一个 CIDR 地址列表,用于在使用 npm token create 命令配置有限访问令牌时使用。

🌐 This is a list of CIDR address to be used when configuring limited access tokens with the npm token create command.

color

  • 默认:除非 NO_COLOR 环境变量设置为非 '0' 的值,否则为 true
  • 类型:"always" 或布尔值

如果为 false,则从不显示颜色。如果为 "always",则始终显示颜色。如果为 true,则仅为 tty 文件描述符打印颜色代码。

🌐 If false, never shows colors. If "always" then always shows colors. If true, then only prints color codes for tty file descriptors.

commit-hooks

  • 默认:是
  • 类型:布尔

在使用 npm version 命令时运行 git 提交钩子。

🌐 Run git commit hooks when using the npm version command.

cpu

  • 默认值:空
  • 类型:空或字符串

覆盖本地模块的 CPU 架构以进行安装。可接受的值与 package.json 的 cpu 字段相同,该字段来自 process.arch

🌐 Override CPU architecture of native modules to install. Acceptable values are same as cpu field of package.json, which comes from process.arch.

depth

  • 默认:如果设置了 --all,则为 Infinity,否则为 1
  • 类型:空或数字

在递归 npm ls 包时要达到的深度。

🌐 The depth to go when recursing packages for npm ls.

如果未设置,npm ls 只会显示根项目的直接依赖。如果设置了 --all,则 npm 默认会显示所有依赖。

🌐 If not set, npm ls will show only the immediate dependencies of the root project. If --all is set, then npm will show all dependencies by default.

description

  • 默认:是
  • 类型:布尔

npm search 中显示描述

🌐 Show the description in npm search

diff

  • 默认值:
  • 类型:字符串(可以多次设置)

npm diff 中定义要比较的参数。

🌐 Define arguments to compare in npm diff.

diff-dst-prefix

  • 默认: "b/"
  • 类型:字符串

npm diff 输出中使用的目标前缀。

🌐 Destination prefix to be used in npm diff output.

diff-ignore-all-space

  • 默认:否
  • 类型:布尔

在比较 npm diff 中的行时忽略空白字符。

🌐 Ignore whitespace when comparing lines in npm diff.

diff-name-only

  • 默认:否
  • 类型:布尔

使用 npm diff 时仅打印文件名。

🌐 Prints only filenames when using npm diff.

diff-no-prefix

  • 默认:否
  • 类型:布尔

npm diff 输出中不要显示任何源或目标前缀。

🌐 Do not show any source or destination prefix in npm diff output.

注意:这会导致 npm diff 忽略 --diff-src-prefix--diff-dst-prefix 配置。

🌐 Note: this causes npm diff to ignore the --diff-src-prefix and --diff-dst-prefix configs.

diff-src-prefix

  • 默认: "a/"
  • 类型:字符串

npm diff 输出中使用的源前缀。

🌐 Source prefix to be used in npm diff output.

diff-text

  • 默认:否
  • 类型:布尔

将所有文件视为 npm diff 中的文本。

🌐 Treat all files as text in npm diff.

diff-unified

  • 默认:3
  • 类型:数字

npm diff 中要打印的上下文行数。

🌐 The number of lines of context to print in npm diff.

dry-run

  • 默认:否
  • 类型:布尔

表示你不希望 npm 做出任何更改,并且它只应该报告本来会做的事情。这个选项可以传递给任何修改本地安装的命令,例如 installupdatededupeuninstall,以及 packpublish

🌐 Indicates that you don't want npm to make any changes and that it should only report what it would have done. This can be passed into any of the commands that modify your local installation, eg, install, update, dedupe, uninstall, as well as pack and publish.

注意:其他与网络相关的命令(例如 dist-tagsowner 等)不支持此项。

🌐 Note: This is NOT honored by other network related commands, eg dist-tags, owner, etc.

editor

  • 默认:EDITOR 或 VISUAL 环境变量,或在 Windows 上为 '%SYSTEMROOT%\notepad.exe',在 Unix 系统上为 'vi'
  • 类型:字符串

运行 npm editnpm config edit 的命令。

🌐 The command to run for npm edit and npm config edit.

engine-strict

  • 默认:否
  • 类型:布尔

如果设置为 true,那么 npm 将顽固地拒绝安装(甚至考虑安装)任何声称与当前 Node.js 版本不兼容的包。

🌐 If set to true, then npm will stubbornly refuse to install (or even consider installing) any package that claims to not be compatible with the current Node.js version.

可以通过设置 --force 标志来覆盖此设置。

🌐 This can be overridden by setting the --force flag.

fetch-retries

  • 默认:2
  • 类型:数字

retry 模块在从注册表获取包时使用的“重试”配置。

🌐 The "retries" config for the retry module to use when fetching packages from the registry.

在网络故障或 5xx HTTP 错误的情况下,npm 将重试对注册表的幂等读取请求。

🌐 npm will retry idempotent read requests to the registry in the case of network failures or 5xx HTTP errors.

fetch-retry-factor

  • 默认:10
  • 类型:数字

retry 模块在获取软件包时使用的“factor”配置。

🌐 The "factor" config for the retry module to use when fetching packages.

fetch-retry-maxtimeout

  • 默认值:60000(1分钟)
  • 类型:数字

retry 模块在获取包时使用的 "maxTimeout" 配置。

🌐 The "maxTimeout" config for the retry module to use when fetching packages.

fetch-retry-mintimeout

  • 默认值:10000(10秒)
  • 类型:数字

retry 模块在获取包时使用的 “minTimeout” 配置。

🌐 The "minTimeout" config for the retry module to use when fetching packages.

fetch-timeout

  • 默认值:300000(5分钟)
  • 类型:数字

等待 HTTP 请求完成的最长时间。

🌐 The maximum amount of time to wait for HTTP requests to complete.

force

  • 默认:否
  • 类型:布尔

删除了针对不幸的副作用、常见错误、不必要的性能下降和恶意输入的各种保护。

🌐 Removes various protections against unfortunate side effects, common mistakes, unnecessary performance degradation, and malicious input.

  • 允许在全局安装中破坏非 npm 文件。
  • 允许 npm version 命令在不干净的 git 仓库上运行。
  • 允许使用 npm cache clean 删除缓存文件夹。
  • 允许安装具有 engines 声明且需要不同版本 npm 的包。
  • 允许安装具有 engines 声明且需要不同版本的 node 的软件包,即使启用了 --engine-strict
  • 允许 npm audit fix 安装超出你指定依赖范围的模块(包括 SemVer 主版本更改)。
  • 允许取消发布已发布包的所有版本。
  • 允许在根项目中安装冲突的 peerDependencies。
  • npm init 期间隐式设置 --yes
  • 允许覆盖 npm pkg 中的现有值
  • 允许取消发布整个包(不仅仅是单个版本)。

如果你对自己想要做什么没有明确的想法,强烈建议你不要使用此选项!

🌐 If you don't have a clear idea of what you want to do, it is strongly recommended that you do not use this option!

foreground-scripts

  • 默认:否
  • 类型:布尔

在前台进程中运行已安装包的所有构建脚本(即 preinstallinstallpostinstall 脚本),并与主 npm 进程共享标准输入、输出和错误。

🌐 Run all build scripts (ie, preinstall, install, and postinstall) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process.

请注意,这通常会使安装运行速度变慢,并且噪音更大,但对调试很有用。

🌐 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.

format-package-lock

  • 默认:是
  • 类型:布尔

package-lock.jsonnpm-shrinkwrap.json 格式化为人类可读的文件。

🌐 Format package-lock.json or npm-shrinkwrap.json as a human readable file.

fund

  • 默认:是
  • 类型:布尔

当“true”显示消息时,会在每个 npm install 的末尾确认正在寻找资金的依赖数量。详情请参见 npm fund

🌐 When "true" displays the message at the end of each npm install acknowledging the number of dependencies looking for funding. See npm fund for details.

git

  • 默认: "git"
  • 类型:字符串

用于 git 命令的命令。如果电脑上安装了 git,但不在 PATH 中,则将此设置为 git 可执行文件的完整路径。

🌐 The command to use for git commands. If git is installed on the computer, but is not in the PATH, then set this to the full path to the git binary.

git-tag-version

  • 默认:是
  • 类型:布尔

在使用 npm version 命令时标记提交。将此设置为 false 则不会进行任何提交。

🌐 Tag the commit when using the npm version command. Setting this to false results in no commit being made at all.

global

  • 默认:否
  • 类型:布尔

以“全局”模式运行,因此软件包会安装到 prefix 文件夹中,而不是当前工作目录。有关行为差异的更多信息,请参见 folders

🌐 Operates in "global" mode, so that packages are installed into the prefix folder instead of the current working directory. See folders for more on the differences in behavior.

  • 软件包被安装到 {prefix}/lib/node_modules 文件夹中,而不是当前工作目录。
  • bin 文件与 {prefix}/bin 关联
  • 手册页已链接到 {prefix}/share/man

globalconfig

  • 默认:全局 --prefix 设置加上 'etc/npmrc'。例如,'/usr/local/etc/npmrc'
  • 类型:路径

为全局配置选项读取的配置文件。

🌐 The config file to read for global config options.

heading

  • 默认: "npm"
  • 类型:字符串

启动所有调试日志输出的字符串。

🌐 The string that starts all the debugging log output.

https-proxy

  • 默认值:空
  • 类型:空或网址

用于外发 HTTPS 请求的代理。如果设置了 HTTPS_PROXYhttps_proxyHTTP_PROXYhttp_proxy 环境变量,底层的 make-fetch-happen 库将会遵循代理设置。

🌐 A proxy to use for outgoing https requests. If the HTTPS_PROXY or https_proxy or HTTP_PROXY or http_proxy environment variables are set, proxy settings will be honored by the underlying make-fetch-happen library.

if-present

  • 默认:否
  • 类型:布尔

如果为真,当执行 run-script 用于 package.jsonscripts 部分中未定义的脚本时,npm 不会以错误码退出。此选项可用于在脚本存在时选择性地运行该脚本,并在脚本执行失败时报错。这在某些情况下非常有用,例如在通常通用的 CI 设置中运行可能只适用于某些构建的脚本时。

🌐 If true, npm will not exit with an error code when run-script is invoked for a script that isn't defined in the scripts section of package.json. This option can be used when it's desirable to optionally run a script when it's present and fail if the script fails. This is useful, for example, when running scripts that may only apply for some builds in an otherwise generic CI setup.

此值不会导出到子进程的环境中。

🌐 This value is not exported to the environment for child processes.

ignore-scripts

  • 默认:否
  • 类型:布尔

如果为 true,npm 不会运行 package.json 文件中指定的脚本。

🌐 If true, npm does not run scripts specified in package.json files.

请注意,明确用于运行特定脚本的命令,例如 npm startnpm stopnpm restartnpm testnpm run-script,如果设置了 ignore-scripts,仍会运行其指定的脚本,但它们不会运行任何前置或后置脚本。

🌐 Note that commands explicitly intended to run a particular script, such as npm start, npm stop, npm restart, npm test, and npm run-script will still run their intended script if ignore-scripts is set, but they will not run any pre- or post-scripts.

include

  • 默认值:
  • 类型:"prod"、"dev"、"optional" 或 "peer"(可以设置多次)

允许定义要安装的依赖类型的选项。

🌐 Option that allows for defining which types of dependencies to install.

这是 --omit=<type> 的逆。

🌐 This is the inverse of --omit=<type>.

--include 中指定的依赖类型不会被忽略,无论命令行中 omit/include 的顺序如何。

🌐 Dependency types specified in --include will not be omitted, regardless of the order in which omit/include are specified on the command-line.

include-staged

  • 默认:否
  • 类型:布尔

允许安装由 npm RFC PR #92 定义的“分阶段”发布的包。

🌐 Allow installing "staged" published packages, as defined by npm RFC PR #92.

这是实验性的,不是由 npm 公共注册表实现的。

🌐 This is experimental, and not implemented by the npm public registry.

include-workspace-root

  • 默认:否
  • 类型:布尔

为命令启用工作区时包括工作区根。

🌐 Include the workspace root when workspaces are enabled for a command.

当为 false 时,通过 workspace 配置指定单个工作区,或通过 workspaces 标志指定所有工作区,将导致 npm 仅在指定的工作区上操作,而不会在根项目上操作。

🌐 When false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project.

此值不会导出到子进程的环境中。

🌐 This value is not exported to the environment for child processes.

init-author-email

  • 默认值:
  • 类型:字符串

默认情况下,应该使用 npm init 作为软件包作者的电子邮件。

🌐 The value npm init should use by default for the package author's email.

init-author-name

  • 默认值:
  • 类型:字符串

默认情况下,应该使用 npm init 作为软件包作者的名称。

🌐 The value npm init should use by default for the package author's name.

init-author-url

  • 默认值:
  • 类型:"" 或 URL

npm init 应默认用于软件包作者的主页。

🌐 The value npm init should use by default for the package author's homepage.

init-license

  • 默认: "ISC"
  • 类型:字符串

包许可默认应使用值 npm init

🌐 The value npm init should use by default for the package license.

init-module

  • 默认: "~/.npm-init.js"
  • 类型:路径

一个将由 npm init 命令加载的模块。更多信息请参见 init-package-json 模块文档,或 npm init

🌐 A module that will be loaded by the npm init command. See the documentation for the init-package-json module for more information, or npm init.

init-version

  • 默认: "1.0.0"
  • 类型:SemVer 字符串

npm init 应默认使用的包版本号值,如果在 package.json 中尚未设置的话。

🌐 The value that npm init should use by default for the package version number, if not already set in package.json.

  • 默认:否
  • 类型:布尔

当设置文件时:协议依赖将作为常规依赖被打包和安装,而不会创建符号链接。此选项对工作区没有影响。

🌐 When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.

install-strategy

  • 默认: "提升"
  • 类型:"提升的"、"嵌套的"、"浅的"或"链接的"

设置在 node_modules 中安装包的策略。hoisted(默认):在顶层安装非重复包,必要时在目录结构中安装重复包。nested(原先为 --legacy-bundling):就地安装,不采用提升。shallow(原先为 --global-style):仅在顶层安装直接依赖。linked(实验性):安装在 node_modules/.store 中,就地链接,不提升。

🌐 Sets the strategy for installing packages in node_modules. hoisted (default): Install non-duplicated in top-level, and duplicated as necessary within directory structure. nested: (formerly --legacy-bundling) install in place, no hoisting. shallow (formerly --global-style) only install direct deps at top-level. linked: (experimental) install in node_modules/.store, link in place, unhoisted.

json

  • 默认:否
  • 类型:布尔

是否输出 JSON 数据,而不是正常输出。

🌐 Whether or not to output JSON data, rather than the normal output.

  • npm pkg set 中,它可以在将值保存到你的 package.json 之前使用 JSON.parse() 解析设置的值。

并非所有 npm 命令都支持。

🌐 Not supported by all npm commands.

legacy-peer-deps

  • 默认:否
  • 类型:布尔

在构建包树时,使 npm 完全忽略 peerDependencies,如 npm 版本 3 到 6 中一样。

🌐 Causes npm to completely ignore peerDependencies when building a package tree, as in npm versions 3 through 6.

如果由于过于严格的 peerDependencies 冲突而无法安装软件包,它提供了一种方法来解决这种情况并继续进行。

🌐 If a package cannot be installed because of overly strict peerDependencies that collide, it provides a way to move forward resolving the situation.

这与 --omit=peer 不同,因为 --omit=peer 会避免在磁盘上解压 peerDependencies,但仍会设计一棵树,使 peerDependencies 可以 在正确的位置被解压。

🌐 This differs from --omit=peer, in that --omit=peer will avoid unpacking peerDependencies on disk, but will still design a tree such that peerDependencies could be unpacked in a correct place.

不推荐使用 legacy-peer-deps,因为它不会强制执行 meta 依赖可能依赖的 peerDependencies 合约。

🌐 Use of legacy-peer-deps is not recommended, as it will not enforce the peerDependencies contract that meta-dependencies may rely on.

  • 默认:否
  • 类型:布尔

npm ls 一起使用,仅限制输出到那些已链接的包。

🌐 Used with npm ls, limiting output to only those packages that are linked.

local-address

  • 默认值:空
  • 类型:IP 地址

在连接 npm 注册表时使用的本地接口的 IP 地址。在 Node 0.12 之前的版本中必须是 IPv4。

🌐 The IP address of the local interface to use when making connections to the npm registry. Must be IPv4 in versions of Node prior to 0.12.

location

  • 默认值:除非传入 --global,否则为 "user",传入后该值也会设置为 "global"
  • 类型:“全局”、“用户”或“项目”

当传递给 npm config 时,这指的是使用哪个配置文件。

🌐 When passed to npm config this refers to which config file to use.

当设置为“全局”模式时,软件包会安装到 prefix 文件夹,而不是当前工作目录。有关行为差异的更多信息,请参见 文件夹

🌐 When set to "global" mode, packages are installed into the prefix folder instead of the current working directory. See folders for more on the differences in behavior.

  • 软件包被安装到 {prefix}/lib/node_modules 文件夹中,而不是当前工作目录。
  • bin 文件与 {prefix}/bin 关联
  • 手册页已链接到 {prefix}/share/man

lockfile-version

  • 默认:如果没有锁定文件,则使用版本3,自动将v1锁定文件转换为v3,否则保持当前锁定文件版本。
  • 类型:null、1、2、3、“1”、“2”或“3”

设置在 package-lock.json 和 npm-shrinkwrap.json 文件中使用的锁文件格式版本。可能的选项有:

🌐 Set the lockfile format version to be used in package-lock.json and npm-shrinkwrap-json files. Possible options are:

1:由 npm 5 和 6 版本使用的锁文件版本。缺少在安装期间使用的一些数据,导致安装速度较慢,可能不够确定。在与旧的 npm 版本互操作时,可以防止锁文件频繁更改。

2:npm 7 和 8 使用的默认锁文件版本。包括版本 1 锁文件数据和版本 3 锁文件数据,以实现最大的确定性和互操作性,但会占用更多磁盘空间。

3:仅在 npm 版本 7 中引入的新锁文件信息。在磁盘上的占用比锁文件版本 2 小,但与旧版本的 npm 不兼容。如果所有用户都使用 npm 版本 7 及以上,这是理想选择。

loglevel

  • 默认: "通知"
  • 类型:“silent”、“error”、“warn”、“notice”、“http”、“info”、“verbose”或“silly”

要报告的日志级别。所有日志都会写入调试日志文件,如果命令执行失败,则会打印该文件的路径。

🌐 What level of logs to report. All logs are written to a debug log, with the path to that file printed if the execution of a command fails.

会显示比设置级别更高的所有日志。默认值是“notice”。

🌐 Any logs of a higher level than the setting are shown. The default is "notice".

另请参阅 foreground-scripts 配置。

🌐 See also the foreground-scripts config.

logs-dir

  • 默认:缓存中名为 _logs 的目录
  • 类型:空或路径

npm 日志目录的位置。更多信息请参见 npm logging

🌐 The location of npm's log directory. See npm logging for more information.

logs-max

  • 默认:10
  • 类型:数字

要存储的最大日志文件数。

🌐 The maximum number of log files to store.

如果设置为 0,则不会为当前运行写入日志文件。

🌐 If set to 0, no log files will be written for the current run.

long

  • 默认:否
  • 类型:布尔

lssearchhelp-search 中显示扩展信息。

🌐 Show extended information in ls, search, and help-search.

maxsockets

  • 默认:15
  • 类型:数字

每个源使用的最大连接数(协议/主机/端口组合)。

🌐 The maximum number of connections to use per origin (protocol/host/port combination).

message

  • 默认: "%s"
  • 类型:字符串

npm version在创建版本提交时使用的提交信息。

🌐 Commit message which is used by npm version when creating version commit.

消息中的任何“%s”将被替换为版本号。

🌐 Any "%s" in the message will be replaced with the version number.

node-options

  • 默认值:空
  • 类型:空或字符串

通过 NODE_OPTIONS 环境变量传递给 Node.js 的选项。这不会影响 npm 本身的执行方式,但会影响生命周期脚本的调用方式。

🌐 Options to pass through to Node.js via the NODE_OPTIONS environment variable. This does not impact how npm itself is executed but it does impact how lifecycle scripts are called.

noproxy

  • 默认值:NO_PROXY 环境变量的值
  • 类型:字符串(可以多次设置)

应该绕过任何代理的域扩展。

🌐 Domain extensions that should bypass any proxies.

还接受逗号分隔的字符串。

🌐 Also accepts a comma-delimited string.

offline

  • 默认:否
  • 类型:布尔

强制离线模式:安装过程中不会进行任何网络请求。若要允许 CLI 填充缺失的缓存数据,请参见 --prefer-offline

🌐 Force offline mode: no network requests will be done during install. To allow the CLI to fill in missing cache data, see --prefer-offline.

omit

  • 默认值:如果 NODE_ENV 环境变量设置为 'production',则为 'dev',否则为空。
  • 类型:“dev”、“optional” 或 “peer”(可以设置多次)

要从磁盘上的安装树中省略的依赖类型。

🌐 Dependency types to omit from the installation tree on disk.

请注意,这些依赖仍然会被解析并添加到 package-lock.jsonnpm-shrinkwrap.json 文件中。它们只是没有实际安装到磁盘上。

🌐 Note that these dependencies are still resolved and added to the package-lock.json or npm-shrinkwrap.json file. They are just not physically installed on disk.

如果某种封装类型同时出现在 --include--omit 列表中,那么它将被包括在内。

🌐 If a package type appears in both the --include and --omit lists, then it will be included.

如果生成的省略列表包含 'dev',那么所有生命周期脚本的 NODE_ENV 环境变量将被设置为 'production'

🌐 If the resulting omit list includes 'dev', then the NODE_ENV environment variable will be set to 'production' for all lifecycle scripts.

omit-lockfile-registry-resolved

  • 默认:否
  • 类型:布尔

此选项会导致 npm 创建不带注册表依赖 resolved 键的锁文件。后续安装将需要使用配置的注册表解析 tar 包端点,可能会导致安装时间更长。

🌐 This option causes npm to create lock files without a resolved key for registry dependencies. Subsequent installs will need to resolve tarball endpoints with the configured registry, likely resulting in a longer install time.

os

  • 默认值:空
  • 类型:空或字符串

覆盖本地模块的操作系统以进行安装。可接受的值与 package.json 的 os 字段相同,该字段来自 process.platform

🌐 Override OS of native modules to install. Acceptable values are same as os field of package.json, which comes from process.platform.

otp

  • 默认值:空
  • 类型:空或字符串

这是来自双因素认证器的一次性密码。在使用 npm access 发布或更改软件包权限时需要此密码。

🌐 This is a one-time password from a two-factor authenticator. It's needed when publishing or changing package permissions with npm access.

如果未设置,并且注册表响应失败并询问一次性密码,npm 将在命令行上提示输入一次密码。

🌐 If not set, and a registry response fails with a challenge for a one-time password, npm will prompt on the command line for one.

pack-destination

  • 默认值:"."
  • 类型:字符串

npm pack 将保存 tar 包的目录。

🌐 Directory in which npm pack will save tarballs.

package

  • 默认值:
  • 类型:字符串(可以多次设置)

要为 npm exec 安装的包

🌐 The package or packages to install for npm exec

package-lock

  • 默认:是
  • 类型:布尔

如果设置为 false,则在安装时忽略 package-lock.json 文件。如果 save 为 true,这也将防止写入 package-lock.json

🌐 If set to false, then ignore package-lock.json files when installing. This will also prevent writing package-lock.json if save is true.

package-lock-only

  • 默认:否
  • 类型:布尔

如果设置为 true,当前操作将只使用 package-lock.json,忽略 node_modules

🌐 If set to true, the current operation will only use the package-lock.json, ignoring node_modules.

对于 update,这意味着只会更新 package-lock.json,而不会检查 node_modules 或下载依赖。

🌐 For update this means only the package-lock.json will be updated, instead of checking node_modules and downloading dependencies.

对于 list,这意味着输出将基于 package-lock.json 描述的树,而不是 node_modules 的内容。

🌐 For list this means the output will be based on the tree described by the package-lock.json, rather than the contents of node_modules.

parseable

  • 默认:否
  • 类型:布尔

从写入标准输出的命令中输出可解析的结果。对于 npm search,这将是制表符分隔的表格格式。

🌐 Output parseable results from commands that write to standard output. For npm search, this will be tab-separated table format.

prefer-dedupe

  • 默认:否
  • 类型:布尔

如果可能,最好对包进行数据去重,而不是选择更新版本的依赖。

🌐 Prefer to deduplicate packages if possible, rather than choosing a newer version of a dependency.

prefer-offline

  • 默认:否
  • 类型:布尔

如果为真,缓存数据的陈旧性检查将被跳过,但缺失的数据将从服务器请求。要强制完全离线模式,请使用 --offline

🌐 If true, staleness checks for cached data will be bypassed, but missing data will be requested from the server. To force full offline mode, use --offline.

prefer-online

  • 默认:否
  • 类型:布尔

如果为 true,将强制检查缓存数据的时效性,使 CLI 立即查找更新,即使是新的包数据也是如此。

🌐 If true, staleness checks for cached data will be forced, making the CLI look for updates immediately even for fresh package data.

prefix

  • 默认:在全局模式下,指的是安装 node 可执行文件的文件夹。否则,指的是包含 package.json 文件或 node_modules 文件夹的最近上级文件夹。
  • 类型:路径

安装全局项目的位置。如果在命令行中设置,则会强制非全局命令在指定文件夹中运行。

🌐 The location to install global items. If set on the command line, then it forces non-global commands to run in the specified folder.

preid

  • 默认值:
  • 类型:字符串

用于作为 semver 中“预发布”部分前缀的“预发布标识符”。就像 1.2.0-rc.8 中的 rc

🌐 The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver. Like the rc in 1.2.0-rc.8.

progress

  • 默认:true,除非在已知的 CI 系统中运行
  • 类型:布尔

当设置为 true 时,如果 process.stderr 是 TTY,npm 会在耗时操作期间显示进度条。

🌐 When set to true, npm will display a progress bar during time intensive operations, if process.stderr is a TTY.

设置为 false 以隐藏进度条。

🌐 Set to false to suppress the progress bar.

provenance

  • 默认:否
  • 类型:布尔

从受支持的云 CI/CD 系统发布时,包将公开链接到它的构建和发布位置。

🌐 When publishing from a supported cloud CI/CD system, the package will be publicly linked to where it was built and published from.

此配置不能与:provenance-file 一起使用

🌐 This config can not be used with: provenance-file

provenance-file

  • 默认值:空
  • 类型:路径

发布时,将使用给定路径的出处包。

🌐 When publishing, the provenance bundle at the given path will be used.

此配置不能与:provenance 一起使用

🌐 This config can not be used with: provenance

proxy

  • 默认值:空
  • 类型:null、false 或 URL

用于发出 HTTP 请求的代理。如果设置了 HTTP_PROXYhttp_proxy 环境变量,底层的 request 库将会遵循代理设置。

🌐 A proxy to use for outgoing http requests. If the HTTP_PROXY or http_proxy environment variables are set, proxy settings will be honored by the underlying request library.

read-only

  • 默认:否
  • 类型:布尔

这用于在使用 npm token create 命令配置有限访问令牌时,将令牌标记为无法发布。

🌐 This is used to mark a token as unable to publish when configuring limited access tokens with the npm token create command.

rebuild-bundle

  • 默认:是
  • 类型:布尔

安装后重建打包的依赖。

🌐 Rebuild bundled dependencies after installation.

registry

  • 默认: "https://registry.npmjs.org/"
  • 类型:网址

npm 注册表的基本 URL。

🌐 The base URL of the npm registry.

replace-registry-host

  • 默认: "npmjs"
  • 类型:"npmjs"、"never"、"always" 或 字符串

定义用配置的注册表替换锁定文件中的注册表主机的行为。

🌐 Defines behavior for replacing the registry host in a lockfile with the configured registry.

默认行为是将包的分发 URL 从默认注册表(https://registry.npmjs.org)替换为配置的注册表。如果设置为“never”,则使用 registry 的值。如果设置为“always”,则每次都将注册表主机替换为配置的主机。

🌐 The default behavior is to replace package dist URLs from the default registry (https://registry.npmjs.org) to the configured registry. If set to "never", then use the registry value. If set to "always", then replace the registry host with the configured host every time.

你也可以指定一个裸主机名(例如,“registry.npmjs.org”)。

🌐 You may also specify a bare hostname (e.g., "registry.npmjs.org").

save

  • 默认:true,除非使用 npm update 时,默认值为 false
  • 类型:布尔

将已安装的软件包保存到 package.json 文件中作为依赖。

🌐 Save installed packages to a package.json file as dependencies.

npm rm 命令一起使用时,会移除对 package.json 的依赖。

🌐 When used with the npm rm command, removes the dependency from package.json.

如果设置为 false,也将阻止向 package-lock.json 写入。

🌐 Will also prevent writing to package-lock.json if set to false.

save-bundle

  • 默认:否
  • 类型:布尔

如果一个包在安装时会通过使用 --save--save-dev--save-optional 保存,那么也应将其放入 bundleDependencies 列表中。

🌐 If a package would be saved at install time by the use of --save, --save-dev, or --save-optional, then also put it in the bundleDependencies list.

如果设置了 --save-peer,将被忽略,因为 peerDependencies 无法被打包。

🌐 Ignored if --save-peer is set, since peerDependencies cannot be bundled.

save-dev

  • 默认:否
  • 类型:布尔

将已安装的包保存到 devDependencies 的 package.json 文件中。

🌐 Save installed packages to a package.json file as devDependencies.

save-exact

  • 默认:否
  • 类型:布尔

保存到 package.json 的依赖将使用精确的版本进行配置,而不是使用 npm 的默认 semver 范围运算符。

🌐 Dependencies saved to package.json will be configured with an exact version rather than using npm's default semver range operator.

save-optional

  • 默认:否
  • 类型:布尔

将已安装的包保存到 optionalDependencies 的 package.json 文件中。

🌐 Save installed packages to a package.json file as optionalDependencies.

save-peer

  • 默认:否
  • 类型:布尔

将已安装的包保存到 package.json 文件中为 peerDependencies

🌐 Save installed packages to a package.json file as peerDependencies

save-prefix

  • 默认: "^"
  • 类型:字符串

配置通过 --save--save-dev 安装到 package.json 文件的包版本如何添加前缀。

🌐 Configure how versions of packages installed to a package.json file via --save or --save-dev get prefixed.

例如,如果一个软件包的版本是 1.2.3,默认情况下其版本会设置为 ^1.2.3,这允许该软件包进行小规模升级,但在 npm config set save-prefix='~' 之后,它将被设置为 ~1.2.3,只允许补丁升级。

🌐 For example if a package has version 1.2.3, by default its version is set to ^1.2.3 which allows minor upgrades for that package, but after npm config set save-prefix='~' it would be set to ~1.2.3 which only allows patch upgrades.

save-prod

  • 默认:否
  • 类型:布尔

将已安装的软件包专门保存到 dependencies。如果一个软件包已经存在于 devDependenciesoptionalDependencies 中,但你想将它移到作为非可选的生产依赖使用,这会很有用。

🌐 Save installed packages into dependencies specifically. This is useful if a package already exists in devDependencies or optionalDependencies, but you want to move it to be a non-optional production dependency.

如果 --save 为真,并且 --save-dev--save-optional 都不为真,这是默认行为。

🌐 This is the default behavior if --save is true, and neither --save-dev or --save-optional are true.

sbom-format

  • 默认值:空
  • 类型:“cyclonedx” 或 “spdx”

生成 SBOM 时使用的 SBOM 格式。

🌐 SBOM format to use when generating SBOMs.

sbom-type

  • 默认: "library"
  • 类型:“库”、“应用”或“框架”

由生成的 SBOM 描述的软件包类型。对于 SPDX,这是 primaryPackagePurpose 字段的值。对于 CycloneDX,这是 type 字段的值。

🌐 The type of package described by the generated SBOM. For SPDX, this is the value for the primaryPackagePurpose field. For CycloneDX, this is the value for the type field.

scope

  • 默认:当前项目的范围(如果有)或
  • 类型:字符串

将操作与范围注册表的作用域相关联。

🌐 Associate an operation with a scope for a scoped registry.

在登录或退出私有注册表时很有用:

🌐 Useful when logging in to or out of a private registry:

# log in, linking the scope to the custom registry
npm login --scope=@mycorp --registry=https://registry.mycorp.com
# log out, removing the link and the auth token
npm logout --scope=@mycorp

这将导致 @mycorp 被映射到注册表中,以便将来根据模式 @mycorp/package 指定的软件包进行安装。

🌐 This will cause @mycorp to be mapped to the registry for future installation of packages specified according to the pattern @mycorp/package.

这也将导致 npm init 创建一个带作用域的包。

🌐 This will also cause npm init to create a scoped package.

# accept all defaults, and create a package named "@foo/whatever",
# instead of just named "whatever"
npm init --scope=@foo --yes

script-shell

  • 默认:在 POSIX 系统上为 '/bin/sh',在 Windows 上为 'cmd.exe'
  • 类型:空或字符串

用于通过 npm execnpm runnpm init <package-spec> 命令运行脚本的 shell。

🌐 The shell to use for scripts run with the npm exec, npm run and npm init <package-spec> commands.

searchexclude

  • 默认值:
  • 类型:字符串

限制搜索结果的空格分隔选项。

🌐 Space-separated options that limit the results from search.

searchlimit

  • 默认:20
  • 类型:数字

要限制搜索结果的项目数量。对旧版搜索完全不适用。

🌐 Number of items to limit search results to. Will not apply at all to legacy searches.

searchopts

  • 默认值:
  • 类型:字符串

始终传递给搜索的空格分隔选项。

🌐 Space-separated options that are always passed to search.

searchstaleness

  • 默认:900
  • 类型:数字

如果使用旧版搜索端点,则在触发另一个注册表请求之前缓存的年龄(以秒为单位)。

🌐 The age of the cache, in seconds, before another registry request is made if using legacy search endpoint.

shell

  • 默认:SHELL 环境变量,Posix 系统上为“bash”,Windows 上为“cmd.exe”
  • 类型:字符串

用于运行 npm explore 命令的 shell。

🌐 The shell to run for the npm explore command.

sign-git-commit

  • 默认:否
  • 类型:布尔

如果设置为 true,则 npm version 命令将使用 -S 提交新软件包版本以添加签名。

🌐 If set to true, then the npm version command will commit the new package version using -S to add a signature.

请注意,git 要求你在 git 配置中设置 GPG 密钥才能正常工作。

🌐 Note that git requires you to have set up GPG keys in your git configs for this to work properly.

sign-git-tag

  • 默认:否
  • 类型:布尔

如果设置为 true,那么 npm version 命令将使用 -s 添加签名来标记版本。

🌐 If set to true, then the npm version command will tag the version using -s to add a signature.

请注意,git 要求你在 git 配置中设置 GPG 密钥才能正常工作。

🌐 Note that git requires you to have set up GPG keys in your git configs for this to work properly.

strict-peer-deps

  • 默认:否
  • 类型:布尔

如果设置为 true,且未设置 --legacy-peer-deps,那么任何冲突的 peerDependencies 都将被视为安装失败,即使 npm 能够基于非 peer 依赖合理地猜测适当的解决方案。

🌐 If set to true, and --legacy-peer-deps is not set, then any conflicting peerDependencies will be treated as an install failure, even if npm could reasonably guess the appropriate resolution based on non-peer dependency relationships.

默认情况下,依赖图中深层的冲突 peerDependencies 将使用最近的非对等依赖规范来解决,即使这样做会导致某些包获得的对等依赖超出其包的 peerDependencies 对象中设置的范围。

🌐 By default, conflicting peerDependencies deep in the dependency graph will be resolved using the nearest non-peer dependency specification, even if doing so will result in some packages receiving a peer dependency outside the range set in their package's peerDependencies object.

当执行此类覆盖时,会打印警告,解释冲突及涉及的包。如果设置了 --strict-peer-deps,则此警告将被视为失败。

🌐 When such an override is performed, a warning is printed, explaining the conflict and the packages involved. If --strict-peer-deps is set, then this warning is treated as a failure.

strict-ssl

  • 默认:是
  • 类型:布尔

通过 https 向注册表触发请求时是否进行 SSL 密钥验证。

🌐 Whether or not to do SSL key validation when making requests to the registry via https.

另请参阅 ca 配置。

🌐 See also the ca config.

tag

  • 默认: "最新"
  • 类型:字符串

如果你让 npm 安装一个包并且没有告诉它一个特定的版本,那么它会安装指定的标签。

🌐 If you ask npm to install a package and don't tell it a specific version, then it will install the specified tag.

同样,如果没有给出明确的标签,npm tag 命令指定的 package@version 也会添加该标签。

🌐 Also the tag that is added to the package@version specified by the npm tag command, if no explicit tag is given.

当被 npm diff 命令使用时,这是用于获取默认将与本地文件进行比较的 tarball 的标签。

🌐 When used by the npm diff command, this is the tag used to fetch the tarball that will be compared with the local files by default.

tag-version-prefix

  • 默认: "v"
  • 类型:字符串

如果设置,在使用 npm version 执行版本递增时,会更改标记新版本时使用的前缀。要完全移除前缀,请将其设置为空字符串:""

🌐 If set, alters the prefix used when tagging a new version when performing a version increment using npm version. To remove the prefix altogether, set it to the empty string: "".

因为其他工具可能依赖于 npm 版本标签看起来像 v1.0.0 的约定,只有在绝对必要时才使用此属性。特别是在为公共包覆盖此设置时要格外谨慎。

🌐 Because other tools may rely on the convention that npm version tags look like v1.0.0, only use this property if it is absolutely necessary. In particular, use care when overriding this setting for public packages.

timing

  • 默认:否
  • 类型:布尔

如果为真,则将时间信息写入缓存中以进程为特定的 JSON 文件或 logs-dir。文件名以 -timing.json 结尾。

🌐 If true, writes timing information to a process specific json file in the cache or logs-dir. The file name ends with -timing.json.

你可以使用这个 json 命令行快速查看它:cat ~/.npm/_logs/*-timing.json | npm exec -- json -g

🌐 You can quickly view it with this json command line: cat ~/.npm/_logs/*-timing.json | npm exec -- json -g.

计时信息也会在终端中报告。若希望在仍然写入计时文件的同时抑制此信息,请使用 --silent

🌐 Timing information will also be reported in the terminal. To suppress this while still writing the timing file, use --silent.

umask

  • 默认:0
  • 类型:八进制数字字符串,范围 0000..0777(0..511)

在设置文件和文件夹的创建模式时使用的“umask”值。

🌐 The "umask" value to use when setting the file creation mode on files and folders.

文件夹和可执行文件会被赋予一个模式,该模式是与此值进行0o777掩码操作的结果。其他文件会被赋予一个模式,该模式是与此值进行0o666掩码操作的结果。

🌐 Folders and executables are given a mode which is 0o777 masked against this value. Other files are given a mode which is 0o666 masked against this value.

请注意,底层系统也会将其自身的 umask 值应用到创建的文件和文件夹上,npm 并不会绕过这一点,而是将 --umask 配置添加到其中。

🌐 Note that the underlying system will also apply its own umask value to files and folders that are created, and npm does not circumvent this, but rather adds the --umask config to it.

因此,大多数 POSIX 系统上有效的默认 umask 值是 0o22,这意味着文件夹和可执行文件以 0o755 模式创建,而其他文件以 0o644 模式创建。

🌐 Thus, the effective default umask value on most POSIX systems is 0o22, meaning that folders and executables are created with a mode of 0o755 and other files are created with a mode of 0o644.

unicode

  • 默认值:在 Windows 上为 false,在 mac/unix 系统上具有 Unicode 本地化环境时为 true,这由 LC_ALLLC_CTYPELANG 环境变量定义。
  • 类型:布尔

当设置为 true 时,npm 在树状输出中使用 Unicode 字符。当设置为 false 时,它使用 ASCII 字符而不是 Unicode 字符。

🌐 When set to true, npm uses unicode characters in the tree output. When false, it uses ascii characters instead of unicode glyphs.

update-notifier

  • 默认:是
  • 类型:布尔

设置为 false 以在使用比最新版本更旧的 npm 时抑制更新通知。

🌐 Set to false to suppress the update notification when using an older version of npm than the latest.

usage

  • 默认:否
  • 类型:布尔

显示有关指定命令的简短用法输出。

🌐 Show short usage output about the command specified.

user-agent

  • 默认: "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}"
  • 类型:字符串

设置 User-Agent 请求头。以下字段将被替换为其实际对应值:

🌐 Sets the User-Agent request header. The following fields are replaced with their actual counterparts:

  • {npm-version} - 使用的 npm 版本
  • {node-version} - 使用的 Node.js 版本
  • {platform} - process.platform 的值
  • {arch} - process.arch 的值
  • {workspaces} - 如果设置了 workspacesworkspace 选项,则设置为 true
  • {ci} - ci-name 配置的值(如果已设置),前面加上 ci/,如果 ci-name 为空,则为一个空字符串。

userconfig

  • 默认: "~/.npmrc"
  • 类型:路径

用户级配置设置的位置。

🌐 The location of user-level configuration settings.

这可能被 npm_config_userconfig 环境变量或 --userconfig 命令行选项覆盖,但 不能globalconfig 文件中的设置覆盖。

🌐 This may be overridden by the npm_config_userconfig environment variable or the --userconfig command line option, but may not be overridden by settings in the globalconfig file.

version

  • 默认:否
  • 类型:布尔

如果为 true,则输出 npm 版本并成功退出。

🌐 If true, output the npm version and exit successfully.

仅在命令行上明确指定时才相关。

🌐 Only relevant when specified explicitly on the command line.

versions

  • 默认:否
  • 类型:布尔

如果为真,输出 npm 版本以及 Node 的 process.versions 映射和当前工作目录下的 package.json 文件中的版本(如果存在),然后成功退出。

🌐 If true, output the npm version as well as node's process.versions map and the version in the current working directory's package.json file if one exists, and exit successfully.

仅在命令行上明确指定时才相关。

🌐 Only relevant when specified explicitly on the command line.

viewer

  • 默认:在 Posix 上为“man”,在 Windows 上为“browser”
  • 类型:字符串

用于查看帮助内容的程序。

🌐 The program to use to view help content.

设置为 "browser" 以在默认的网页浏览器中查看 HTML 帮助内容。

🌐 Set to "browser" to view html help content in the default web browser.

which

  • 默认值:空
  • 类型:空或数字

如果有多个资金来源,打开哪个 1-indexed 来源 URL。

🌐 If there are multiple funding sources, which 1-indexed source URL to open.

workspace

  • 默认值:
  • 类型:字符串(可以多次设置)

启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。

🌐 Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.

workspace 配置的有效值为以下之一:

🌐 Valid values for the workspace config are either:

  • 工作区名称
  • 工作区目录的路径
  • 父工作区目录的路径(将导致选择该文件夹中的所有工作区)

对于 npm init 命令设置时,可以将其设置为一个尚不存在的工作区文件夹,以创建该文件夹并将其作为项目内全新的工作区进行设置。

🌐 When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.

此值不会导出到子进程的环境中。

🌐 This value is not exported to the environment for child processes.

workspaces

  • 默认值:空
  • 类型:空或布尔值

设置为 true 以在 所有 配置的工作区上下文中运行命令。

🌐 Set to true to run the command in the context of all configured workspaces.

将此显式设置为 false 会导致像 install 这样的命令完全忽略工作区。如果不显式设置:

🌐 Explicitly setting this to false will cause commands like install to ignore workspaces altogether. When not set explicitly:

  • node_modules 树操作的命令(安装、更新等)会将工作区链接到 node_modules 文件夹。- 执行其他操作的命令(测试、执行、发布等)会在根项目上运行,除非workspace 配置中指定了一个或多个工作区。

此值不会导出到子进程的环境中。

🌐 This value is not exported to the environment for child processes.

workspaces-update

  • 默认:是
  • 类型:布尔

如果设置为 true,npm CLI 将在可能更改安装到 node_modules 文件夹中的工作区的操作之后运行更新。

🌐 If set to true, the npm cli will run an update after operations that may possibly change the workspaces installed to the node_modules folder.

yes

  • 默认值:空
  • 类型:空或布尔值

自动对 npm 在命令行上可能显示的任何提示回答“是”。

🌐 Automatically answer "yes" to any prompts that npm might print on the command line.

also

  • 默认值:空
  • 类型:null、“dev”或“development”
  • 已弃用:请改用 --include=dev。

当设置为 devdevelopment 时,这是 --include=dev 的别名。

🌐 When set to dev or development, this is an alias for --include=dev.

cache-max

  • 默认值:无限
  • 类型:数字
  • 已弃用:此选项已被弃用,建议使用 --prefer-online

--cache-max=0--prefer-online 的别名

cache-min

  • 默认:0
  • 类型:数字
  • 已弃用:此选项已被弃用,建议使用 --prefer-offline

--cache-min=9999 (or bigger)--prefer-offline 的别名。

cert

  • 默认值:空
  • 类型:空或字符串
  • 已弃用:keycert 在大多数注册表操作中不再使用。请改为使用注册表范围的 keyfilecertfile。示例://other-registry.tld/:keyfile=/path/to/key.pem //other-registry.tld/:certfile=/path/to/cert.crt

访问注册表时需要提供的客户端证书。证书的值应采用 PEM 格式(Windows 称之为“Base-64 编码的 X.509 (.CER)”),并将换行符替换为字符串 "\n"。例如:

🌐 A client certificate to pass when accessing the registry. Values should be in PEM format (Windows calls it "Base-64 encoded X.509 (.CER)") with newlines replaced by the string "\n". For example:

cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

这并不是证书文件的路径,不过你可以设置一个注册表范围的“certfile”路径,例如“//other-registry.tld/:certfile=/path/to/cert.pem”。

🌐 It is not the path to a certificate file, though you can set a registry-scoped "certfile" path like "//other-registry.tld/:certfile=/path/to/cert.pem".

ci-name

  • 默认:当前 CI 系统的名称,或在未使用已知 CI 平台时为 null
  • 类型:空或字符串
  • 已弃用:此配置已被弃用,在未来版本的 npm 中将无法更改。

连续集成系统的名称。如果未明确设置,npm 将使用 ci-info 模块检测当前的 CI 环境。

🌐 The name of a continuous integration system. If not set explicitly, npm will detect the current CI environment using the ci-info module.

dev

  • 默认:否
  • 类型:布尔
  • 已弃用:请改用 --include=dev。

--include=dev 的别名。

🌐 Alias for --include=dev.

global-style

  • 默认:否
  • 类型:布尔
  • 已弃用:此选项已被 --install-strategy=shallow 取代

只在顶层 node_modules 安装直接依赖,但在更深层的依赖上使用提升(hoist)。设置 --install-strategy=shallow

🌐 Only install direct dependencies in the top level node_modules, but hoist on deeper dependencies. Sets --install-strategy=shallow.

init.author.email

  • 默认值:
  • 类型:字符串
  • 已弃用:请改用 --init-author-email

--init-author-email 的别名

🌐 Alias for --init-author-email

init.author.name

  • 默认值:
  • 类型:字符串
  • 已弃用:请改用 --init-author-name

--init-author-name 的别名

🌐 Alias for --init-author-name

init.author.url

  • 默认值:
  • 类型:"" 或 URL
  • 已弃用:请改用 --init-author-url

--init-author-url 的别名

🌐 Alias for --init-author-url

init.license

  • 默认: "ISC"
  • 类型:字符串
  • 已弃用:请改用 --init-license

--init-license 的别名

🌐 Alias for --init-license

init.module

  • 默认: "~/.npm-init.js"
  • 类型:路径
  • 已弃用:请改用 --init-module

--init-module 的别名

🌐 Alias for --init-module

init.version

  • 默认: "1.0.0"
  • 类型:SemVer 字符串
  • 已弃用:请改用 --init-version

--init-version 的别名

🌐 Alias for --init-version

key

  • 默认值:空
  • 类型:空或字符串
  • 已弃用:keycert 在大多数注册表操作中不再使用。请改为使用注册表范围的 keyfilecertfile。示例://other-registry.tld/:keyfile=/path/to/key.pem //other-registry.tld/:certfile=/path/to/cert.crt

访问注册表时需要传递的客户端密钥。值应为 PEM 格式,并将换行符替换为字符串“\n”。例如:

🌐 A client key to pass when accessing the registry. Values should be in PEM format with newlines replaced by the string "\n". For example:

key="-----BEGIN PRIVATE KEY-----\nXXXX\nXXXX\n-----END PRIVATE KEY-----"

这不是指向密钥文件的路径,不过你可以设置一个注册表范围的“keyfile”路径,例如“//other-registry.tld/:keyfile=/path/to/key.pem”。

🌐 It is not the path to a key file, though you can set a registry-scoped "keyfile" path like "//other-registry.tld/:keyfile=/path/to/key.pem".

legacy-bundling

  • 默认:否
  • 类型:布尔
  • 已弃用:此选项已被弃用,建议使用 --install-strategy=nested

不要在 node_modules 中提升包安装,而是按照依赖的方式安装包。这可能会导致非常深的目录结构和重复的包安装,因为没有去重功能。设置 --install-strategy=nested

🌐 Instead of hoisting package installs in node_modules, install packages in the same manner that they are depended on. This may cause very deep directory structures and duplicate package installs as there is no de-duplicating. Sets --install-strategy=nested.

only

  • 默认值:空
  • 类型:null、“prod”或“production”
  • 已弃用:请使用 --omit=dev 来在安装时省略开发依赖。

当设置为 prodproduction 时,这是 --omit=dev 的别名。

🌐 When set to prod or production, this is an alias for --omit=dev.

optional

  • 默认值:空
  • 类型:空或布尔值
  • 已弃用:使用 --omit=optional 排除可选依赖,或使用 --include=optional 包含它们。

除非另有省略,否则默认值会安装可选的 deps。

🌐 Default value does install optional deps unless otherwise omitted.

--include=optional 或 --omit=optional 的别名

🌐 Alias for --include=optional or --omit=optional

production

  • 默认值:空
  • 类型:空或布尔值
  • 已弃用:请改用 --omit=dev

--omit=dev 的别名

🌐 Alias for --omit=dev

shrinkwrap

  • 默认:是
  • 类型:布尔
  • 已弃用:请改用 --package-lock 设置。

--package-lock 的别名

🌐 Alias for --package-lock

tmp

历史上,用于存放临时文件的位置。现在已不再相关。

🌐 Historically, the location where temporary files were stored. No longer relevant.

也可以看看

🌐 See also

目录