npm-install

Install a package安装程序包

Synopsis提要




npm install [<package-spec> ...]
aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall

Description描述

This command installs a package and any packages that it depends on. 此命令安装一个程序包及其所依赖的任何程序包。If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock file, the installation of dependencies will be driven by that, respecting the following order of precedence:如果程序包具有程序包锁、npm包覆面提取文件或纱线锁文件,则依赖项的安装将由其驱动,并遵循以下优先顺序:

  • npm-shrinkwrap.json
  • package-lock.json
  • yarn.lock

See package-lock.json and npm shrinkwrap.请参阅package-lock.jsonnpm shrinkwrap

A package is:一个package是:

  • a) a folder containing a program described by a package.json file包含由package.json文件描述的程序的文件夹
  • b) a gzipped tarball containing (a)含有(a)的gzip压缩tarball
  • c) a url that resolves to (b)解析为(b)的URL
  • d) a <name>@<version> that is published on the registry (see registry) with (c)使用(c)在注册表上发布的<name>@<version>(请参阅registry
  • e) a <name>@<tag> (see npm dist-tag) that points to (d)指向(d)的<name>@<tag>(参见npm dist-tag
  • f) a <name> that has a "latest" tag satisfying (e)具有满足(e)的“最新”标签的<name>
  • g) a <git remote url> that resolves to (a)一个解析为(a)的<git remote url>

Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b).即使您从未发布过您的包,如果您只想编写一个节点程序(a),或者如果您还想在将其打包到tarball(b)中后轻松地将其安装到其他地方,那么使用npm仍然可以获得很多好处。

  • npm install (in a package directory, no arguments):(在包目录中,没有参数):

    Install the dependencies to the local node_modules folder.将依赖项安装到本地node_modules文件夹中。

    In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.在全局模式下(即,在命令后附加-g--global),它将当前包上下文(即当前工作目录)作为全局包安装。

    By default, npm install will install all modules listed as dependencies in package.json.默认情况下,npm install将安装package.json中作为依赖项列出的所有模块。

    With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies. 使用--production标志(或者当NODE_ENV环境变量设置为production时),npm将不会安装devDependencies中列出的模块。To install all modules listed in both dependencies and devDependencies when NODE_ENV environment variable is set to production, you can use --production=false.NODE_ENV环境变量设置为production时,要安装dependenciesdevDependencies中列出的所有模块,可以使用--production=false

    NOTE: The --production flag has no particular meaning when adding a dependency to a project.当向项目添加依赖项时,--production标志没有特别的含义。

  • npm install <folder>:

    If <folder> sits inside the root of your project, its dependencies will be installed and may be hoisted to the top-level node_modules as they would for other types of dependencies. 如果<folder>位于项目的根目录中,它的依赖项将被安装,并可能被提升到顶级node_modules,就像其他类型的依赖项一样。If <folder> sits outside the root of your project, npm will not install the package dependencies in the directory <folder>, but it will create a symlink to <folder>.如果<folder>位于项目的根目录之外,npm将不会在<folder>目录中安装包依赖项,但它将创建一个指向<folder>的符号链接。

    NOTE: If you want to install the content of a directory like a package from the registry instead of creating a link, you would need to use the --install-links option.注意:如果您想从注册表中安装目录的内容,如软件包,而不是创建链接,则需要使用--install-links选项。

    Example:例子:

    
    
    
    
    npm install ../../other-package --install-links
    npm install ./sub-package
  • npm install <tarball file>:

    Install a package that is sitting on the filesystem. 安装位于文件系统上的软件包。Note: if you just want to link a dev directory into your npm root, you can do this more easily by using npm link.注意:如果您只想将一个dev目录链接到您的npm根目录,那么可以通过使用npm link更容易地做到这一点。

    Tarball requirements:Tarball要求:

    • The filename must use .tar, .tar.gz, or .tgz as the extension.文件名必须使用.tar.tar.gz.tgz作为扩展名。

    • The package contents should reside in a subfolder inside the tarball (usually it is called package/). 包内容应该位于tarball中的子文件夹中(通常称为package/)。npm strips one directory layer when installing the package (an equivalent of tar x --strip-components=1 is run).npm在安装包时剥离一个目录层(运行相当于tar x --strip-components=1的程序)。

    • The package must contain a package.json file with name and version properties.该包必须包含一个具有nameversion属性的package.json文件。

      Example:例子:

      
      
      
      
      npm install ./package.tgz
  • npm install <tarball url>:

    Fetch the tarball url, and then install it. In order to distinguish between this and other options, the argument must start with "http://" or "https://"获取tarball url,然后安装它。为了区分此选项和其他选项,参数必须以“http://”或“https://”开头。

    Example:例子:

    
    
    
    
    npm install https://github.com/indexzero/forever/tarball/v0.5.6
  • npm install [<@scope>/]<name>:

    Do a <name>@<tag> install, where <tag> is the "tag" config. 执行<name>@<tag>安装,其中<tag>是“标记”配置。(See config. (参见configThe config's default value is latest.)配置的默认值是latest。)

    In most cases, this will install the version of the modules tagged as latest on the npm registry.在大多数情况下,这将在npm注册表中安装标记为latest的模块版本。

    Example:例子:

    
    
    
    
    npm install sax

    npm install saves any specified packages into dependencies by default. 默认情况下,npm install会将任何指定的包保存到依赖项中。Additionally, you can control where and how they get saved with some additional flags:此外,您还可以使用一些附加标志来控制它们的保存位置和方式:

    • -P, --save-prod: Package will appear in your dependencies. :包将显示在您的dependencies中。This is the default unless -D or -O are present.除非存在-D-O,否则这是默认设置。

    • -D, --save-dev: Package will appear in your devDependencies.:包将出现在您的devDependencies中。

    • -O, --save-optional: Package will appear in your optionalDependencies.:程序包将显示在您的optionalDependencies中。

    • --no-save: Prevents saving to dependencies.:防止保存到dependencies

      When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:当使用上述任何选项将依赖项保存到您的package.json时,还有两个额外的可选标志:

    • -E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator.:保存的依赖项将使用精确的版本进行配置,而不是使用npm的默认semver范围运算符。

    • -B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.:保存的依赖项也将添加到bundleDependencies列表中。

      Further, if you have an npm-shrinkwrap.json or package-lock.json then it will be updated as well.此外,如果您有一个npm-shrinkwrap.jsonpackage-lock.json,那么它也会被更新。

      <scope> is optional. 是可选的。The package will be downloaded from the registry associated with the specified scope. 将从与指定作用域关联的注册表中下载该程序包。If no registry is associated with the given scope the default registry is assumed. 如果没有注册表与给定的作用域相关联,则假定为默认注册表。See scope.请参阅scope

      Note: if you do not include the @-symbol on your scope name, npm will interpret this as a GitHub repository instead, see below. Scopes names must also be followed by a slash.注意:如果你的作用域名称中没有包含@符号,npm会将其解释为GitHub存储库,请参阅下文。作用域名称后面还必须跟一个斜线。

      Examples:例子:

      
      
      
      
      npm install sax
      npm install githubname/reponame
      npm install @myorg/privatepackage
      npm install node-tap --save-dev
      npm install dtrace-provider --save-optional
      npm install readable-stream --save-exact
      npm install ansi-regex --save-bundle

      Note: If there is a file or folder named <name> in the current working directory, then it will try to install that, and only try to fetch the package by name if it is not valid.如果当前工作目录中有一个名为<name>的文件或文件夹,则它将尝试安装该文件或文件夹。只有在无效时,它才会尝试按名称获取包。

  • npm install <alias>@npm:<name>:

    Install a package under a custom alias. Allows multiple versions of a same-name package side-by-side, more convenient import names for packages with otherwise long ones, and using git forks replacements or forked npm packages as replacements. 使用自定义别名安装程序包。允许同一名称包的多个版本并行,为具有较长名称的包更方便地导入名称,并使用git forks替换或forked npm包作为替换。Aliasing works only on your project and does not rename packages in transitive dependencies. 别名仅适用于您的项目,不会重命名具有可传递依赖关系的包。Aliases should follow the naming conventions stated in validate-npm-package-name.别名应遵循validate-npm-package-name中规定的命名约定。

    Examples:例子:

    
    
    
    
    npm install my-react@npm:react
    npm install jquery2@npm:jquery@2
    npm install jquery3@npm:jquery@3
    npm install npa@npm:npm-package-arg
  • npm install [<@scope>/]<name>@<tag>:

    Install the version of the package that is referenced by the specified tag. If the tag does not exist in the registry data for that package, then this will fail.安装指定标记所引用的程序包的版本。如果该包的注册表数据中不存在该标记,则此操作将失败。

    Example:例子:

    
    
    
    
    npm install sax@latest
    npm install @myorg/mypackage@latest
  • npm install [<@scope>/]<name>@<version>:

    Install the specified version of the package. 安装指定版本的程序包。This will fail if the version has not been published to the registry.如果版本尚未发布到注册表,则此操作将失败。

    Example:例子:

    
    
    
    
    npm install sax@0.1.1
    npm install @myorg/privatepackage@1.5.0
  • npm install [<@scope>/]<name>@<version range>:

    Install a version of the package matching the specified version range. 安装与指定版本范围匹配的程序包版本。This will follow the same rules for resolving dependencies described in package.json.这将遵循package.json中描述的解析依赖关系的相同规则。

    Note that most version ranges must be put in quotes so that your shell will treat it as a single argument.请注意,大多数版本范围都必须加引号,这样您的shell才会将其视为单个参数。

    Example:例子:

    
    
    npm install sax@">=0.1.0 <0.2.0"
    npm install @myorg/privatepackage@"16 - 17"
  • npm install <git remote url>:

    Installs the package from the hosted git provider, cloning it with git. 从托管的git提供程序安装包,并使用git进行克隆。For a full git remote url, only that URL will be attempted.对于完整的git远程url,只会尝试该url。

    
    
    <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]

    <protocol> is one of git, git+ssh, git+http, git+https, or git+file.gitgit+sshgit+httpgit+httpsgit+file之一。

    If #<commit-ish> is provided, it will be used to clone exactly that commit. 如果提供了#<commit-ish>,它将用于克隆该提交。If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. 如果提交ish的格式为#semver:<semver>,则<semver>可以是任何有效的semver范围或确切版本,npm将在远程存储库中查找与该范围匹配的任何标记或引用,就像查找注册表依赖项一样。If neither #<commit-ish> or #semver:<semver> is specified, then the default branch of the repository is used.如果没有指定#<commit-ish>#semver:<semver>,则使用存储库的默认分支。

    If the repository makes use of submodules, those submodules will be cloned as well.如果存储库使用子模块,那么这些子模块也将被克隆。

    If the package being installed contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.如果正在安装的包包含一个prepare脚本,则在打包和安装包之前,将安装其dependenciesdevDependencies,并运行准备脚本。

    The following git environment variables are recognized by npm and will be added to the environment when running git:以下git环境变量由npm识别,并将在运行git时添加到环境中:

    • GIT_ASKPASS

    • GIT_EXEC_PATH

    • GIT_PROXY_COMMAND

    • GIT_SSH

    • GIT_SSH_COMMAND

    • GIT_SSL_CAINFO

    • GIT_SSL_NO_VERIFY

      See the git man page for details.有关详细信息,请参阅git手册页。

      Examples:例子:

      
      
      npm install git+ssh://git@github.com:npm/cli.git#v1.0.27
      npm install git+ssh://git@github.com:npm/cli#pull/273
      npm install git+ssh://git@github.com:npm/cli#semver:^5.0
      npm install git+https://isaacs@github.com/npm/cli.git
      npm install git://github.com/npm/cli.git#v1.0.27
      GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/cli.git
  • npm install <githubname>/<githubrepo>[#<commit-ish>]:

  • npm install github:<githubname>/<githubrepo>[#<commit-ish>]:

    Install the package at https://github.com/githubname/githubrepo by attempting to clone it using git.将程序包安装在https://github.com/githubname/githubrepo通过尝试使用git克隆它。

    If #<commit-ish> is provided, it will be used to clone exactly that commit. 如果提供了#<commit-ish>,它将用于克隆该提交。If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. 如果提交ish的格式为#semver:<semver>,则<semver>可以是任何有效的semver范围或确切版本,npm将在远程存储库中查找与该范围匹配的任何标记或引用,就像查找注册表依赖项一样。If neither #<commit-ish> or #semver:<semver> is specified, then the default branch is used.如果没有指定#<commit-ish>#semver:<semver>,则使用默认分支。

    As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script before the package is done installing.与常规的git依赖项一样,如果包在安装完成之前有一个prepare脚本,那么将安装dependenciesdevDependencies

    Examples:例子:

    
    
    npm install mygithubuser/myproject
    npm install github:mygithubuser/myproject
  • npm install gist:[<githubname>/]<gistID>[#<commit-ish>|#semver:<semver>]:

    Install the package at https://gist.github.com/gistID by attempting to clone it using git. 将程序包安装在https://gist.github.com/gistID通过尝试使用git克隆它。The GitHub username associated with the gist is optional and will not be saved in package.json.与gist关联的GitHub用户名是可选的,不会保存在package.json中。

    As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script before the package is done installing.与常规的git依赖项一样,如果包在安装完成之前有一个prepare脚本,那么将安装dependenciesdevDependencies

    Example:例子:

    
    
    npm install gist:101a11beef
  • npm install bitbucket:<bitbucketname>/<bitbucketrepo>[#<commit-ish>]:

    Install the package at https://bitbucket.org/bitbucketname/bitbucketrepo by attempting to clone it using git.将程序包安装在https://bitbucket.org/bitbucketname/bitbucketrepo通过尝试使用git克隆它。

    If #<commit-ish> is provided, it will be used to clone exactly that commit. 如果提供了#<commit-ish>,它将用于克隆该提交。If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. 如果提交ish的格式为#semver:<semver>,则<semver>可以是任何有效的semver范围或确切版本,npm将在远程存储库中查找与该范围匹配的任何标记或引用,就像查找注册表依赖项一样。If neither #<commit-ish> or #semver:<semver> is specified, then master is used.如果没有指定#<commit-ish>#semver:<semver>,则使用master

    As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script before the package is done installing.与常规的git依赖项一样,如果包在安装完成之前有一个prepare脚本,那么将安装dependenciesdevDependencies

    Example:例子:

    
    
    npm install bitbucket:mybitbucketuser/myproject
  • npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]:

    Install the package at https://gitlab.com/gitlabname/gitlabrepo by attempting to clone it using git.将程序包安装在https://gitlab.com/gitlabname/gitlabrepo通过尝试使用git克隆它。

    If #<commit-ish> is provided, it will be used to clone exactly that commit. 如果提供了#<commit-ish>,它将用于克隆该提交。If the commit-ish has the format #semver:<semver>, <semver> can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. If neither #<commit-ish> or #semver:<semver> is specified, then master is used.

    As with regular git dependencies, dependencies and devDependencies will be installed if the package has a prepare script before the package is done installing.

    Example:例子:

    
    
    npm install gitlab:mygitlabuser/myproject
    npm install gitlab:myusr/myproj#semver:^5.0

You may combine multiple arguments and even multiple types of arguments. For example:您可以组合多个参数,甚至可以组合多种类型的参数。例如:


npm install sax@">=0.1.0 <0.2.0" bench supervisor

The --tag argument will apply to all of the specified install targets. --tag参数将应用于所有指定的安装目标。If a tag with the given name exists, the tagged version is preferred over newer versions.如果存在具有给定名称的标记,则标记版本优先于较新版本。

The --dry-run argument will report in the usual way what the install would have done without actually installing anything.--dry-run参数将以通常的方式报告在没有实际安装任何东西的情况下安装会做什么。

The --package-lock-only argument will only update the package-lock.json, instead of checking node_modules and downloading dependencies.--package-lock-only参数只会更新package-lock.json,而不会检查node_modules和下载依赖项。

The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk.-f-force参数将强制npm获取远程资源,即使磁盘上存在本地副本也是如此。


npm install sax --force

Configuration

See the config help doc. 请参阅config帮助文档。Many of the configuration params have some effect on installation, since that's most of what npm does.许多配置参数对安装有一定的影响,因为这是npm所做的大部分工作。

These are some of the most common options related to installation.这些是与安装相关的一些最常见的选项。

save

  • Default: true unless when using npm update where it defaults to false
  • Type: Boolean

Save installed packages to a package.json file as dependencies.将已安装的包作为依赖项保存到package.json文件中。

When used with the npm rm command, removes the dependency from package.json.当与npm rm命令一起使用时,会从package.json中删除依赖项。

Will also prevent writing to package-lock.json if set to false.如果设置为false,还将阻止写入package-lock.json

save-exact

  • Default: false
  • Type: Boolean

Dependencies saved to package.json will be configured with an exact version rather than using npm's default semver range operator.保存到package.json的依赖项将使用精确的版本进行配置,而不是使用npm的默认semver范围运算符。

global

  • Default: false
  • Type: Boolean

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.

  • packages are installed into the {prefix}/lib/node_modules folder, instead of the current working directory.
  • bin files are linked to {prefix}/bin
  • man pages are linked to {prefix}/share/man

install-strategy

  • Default: "hoisted"
  • Type: "hoisted", "nested", "shallow", or "linked"

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.

legacy-bundling

  • Default: false
  • Type: Boolean
  • DEPRECATED: This option has been deprecated in favor of --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.

global-style

  • Default: false
  • Type: Boolean
  • DEPRECATED: This option has been deprecated in favor of --install-strategy=shallow

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

omit

  • Default: 'dev' if the NODE_ENV environment variable is set to 'production', otherwise empty.
  • Type: "dev", "optional", or "peer" (can be set multiple times)

Dependency types to omit from the installation tree on disk.要从磁盘上的安装树中省略的依赖项类型。

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.它们只是没有物理安装在磁盘上。

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

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

strict-peer-deps

  • Default: false
  • Type: Boolean

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.

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.

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.

package-lock

  • Default: true
  • Type: Boolean

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

This configuration does not affect npm ci.

foreground-scripts

  • Default: false
  • Type: Boolean

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.请注意,这通常会使安装运行速度变慢,噪音更大,但对调试很有用。

ignore-scripts

  • Default: false
  • Type: Boolean

If true, npm does not run scripts specified in package.json files.如果为true,则npm不会运行package.json文件中指定的脚本。

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.

audit

  • Default: true
  • Type: Boolean

When "true" submit audit reports alongside the current npm command to the default registry and all registries configured for scopes. 当“true”时,将审核报告与当前npm命令一起提交到默认注册表和为作用域配置的所有注册表。See the documentation for npm audit for details on what is submitted.

  • Default: true
  • Type: Boolean

Tells npm to create symlinks (or .cmd shims on Windows) for package executables.告诉npm为包可执行文件创建符号链接(或Windows上的.cmd垫片)。

Set to false to have it not do this. 设置为false以使其不执行此操作。This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems.这可以用来解决一些文件系统不支持符号链接的问题,即使是在表面上的Unix系统上。

fund

  • Default: true
  • Type: Boolean

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.

dry-run

  • Default: false
  • Type: Boolean

Indicates that you don't want npm to make any changes and that it should only report what it would have done. 表示您不希望npm进行任何更改,并且它应该只报告它将要做的事情。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.

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

workspace

  • Default:
  • Type: String (can be set multiple times)

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.启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行筛选。

Valid values for the workspace config are either:

  • Workspace names工作区名称
  • Path to a workspace directory工作区目录的路径
  • Path to a parent workspace directory (will result in selecting all workspaces within that folder)父工作区目录的路径(将导致选择该文件夹中的所有工作区)

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

  • Default: null
  • Type: null or Boolean

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

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

  • Commands that operate on the node_modules tree (install, update, etc.) will link workspaces into the node_modules folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, unless one or more workspaces are specified in the workspace config.

This value is not exported to the environment for child processes.此值不会导出到子进程的环境中。

include-workspace-root

  • Default: false
  • Type: Boolean

Include the workspace root when workspaces are enabled for a command.为命令启用工作空间时,包括工作空间根。

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.此值不会导出到子进程的环境中。

  • Default: false
  • Type: Boolean

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.当设置文件时:协议依赖项将被打包并安装为常规依赖项,而不是创建符号链接。此选项对工作空间没有影响。

Algorithm

Given a package{dep} structure: A{B,C}, B{C}, C{D}, the npm install algorithm produces:




A
+-- B
+-- C
+-- D

That is, the dependency from B to C is satisfied by the fact that A already caused C to be installed at a higher level. D is still installed at the top level because nothing conflicts with it.也就是说,从B到C的依赖性是由A已经导致C被安装在更高级别的事实来满足的。D仍然安装在顶层,因为没有任何冲突。

For A{B,C}, B{C,D@1}, C{D@2}, this algorithm produces:




A
+-- B
+-- C
`-- D@2
+-- D@1

Because B's D@1 will be installed in the top-level, C now has to install D@2 privately for itself. This algorithm is deterministic, but different trees may be produced if two dependencies are requested for installation in a different order.

See folders for a more detailed description of the specific folder structures that npm creates.

See Also