Skip to main content

错误代码

信息

你是插件作者,想要声明自己的错误代码,而这些错误代码与此处提供的语义不匹配吗?请放弃一个字符并使用 YNX 前缀(例如 YNX001)而不是 YN0

¥Are you a plugin author and want to declare your own error codes that don't match the semantic of the ones provided here? Please relinquish one character and use the YNX prefix (ex YNX001) instead of YN0!

遵守这一惯例将帮助我们的用户找出哪些错误代码可以在此文档中找到,哪些错误代码应该根据他们使用的插件的单独文档进行检查。

¥Keeping this convention will help our users to figure out which error codes can be found on this documentation and which ones should instead be checked against the individual documentation of the plugins they use.

YN0000 - UNNAMED

此代码用于记录常规消息,主要用于对齐 Yarn 输出中的所有行。不用担心!

¥This code is used to log regular messages, mostly to align all the lines in the Yarn output. No worry!

YN0001 - EXCEPTION

程序抛出了异常。

¥An exception had be thrown by the program.

此错误通常不应该发生(它应该指向此页面中的其他错误消息,以便可以正确记录),因此应将其视为 Yarn 中的错误。请随时打开问题,或者更好的是,提出旨在修复它的拉取请求。

¥This error typically should never happen (it should instead point to a different error message from this page so that it can be properly documented), so it should be considered a bug in Yarn. Feel free to open an issue or, even better, a pull request aiming to fix it.

YN0002 - MISSING_PEER_DEPENDENCY

包请求对等依赖,但依赖树中的一个或多个父级不提供它。

¥A package requests a peer dependency, but one or more of its parents in the dependency tree doesn't provide it.

请注意,Yarn 在依赖树的每个级别都强制执行对等依赖。也就是说,如果 ─D> 是依赖,而 ─P> 是同级依赖,

¥Note that Yarn enforces peer dependencies at every level of the dependency tree. That is, if ─D> is a dependency and ─P> is a peer dependency,

# bad
project
├─D> packagePeer
└─D> packageA
└─P> packageB
└─P> packagePeer

# good
project
├─D> packagePeer
└─D> packageA
├─P> packagePeer
└─D> packageB
└─P> packagePeer

根据你的情况,可能有多个选项:

¥Depending on your situation, multiple options are possible:

  • packageA 的作者可以通过在 packagePeer 上添加对等依赖来解决此问题。如果相关,他们可以使用 可选的对等依赖 来实现此效果。

    ¥The author of packageA can fix this problem by adding a peer dependency on packagePeer. If relevant, they can use optional peer dependencies to this effect.

  • packageB 的作者可以通过将 packagePeer 对等依赖标记为可选来解决此问题 - 但当然,前提是同级依赖实际上是可选的!

    ¥The author of packageB can fix this problem by marking the packagePeer peer dependency as optional - but only if the peer dependency is actually optional, of course!

  • project 的作者可以通过手动覆盖 packageExtensions 配置选项 上的 packageA 和/或 packageB 定义来解决此问题。

    ¥The author of project can fix this problem by manually overriding the packageA and/or packageB definitions via the packageExtensions config option.

要了解有关此问题的更多信息,请查看 这篇博文

¥To understand more about this issue, check out this blog post.

YN0003 - CYCLIC_DEPENDENCIES

带有构建脚本的两个包具有循环依赖。

¥Two packages with build scripts have cyclic dependencies.

循环依赖是一个蠕虫罐。当包 A 依赖于包 B 时,它们就会发生,反之亦然。有时可以通过多个包的链接出现 - 例如当 A 依赖于 B 时,B 依赖于 CC 依赖于 A

¥Cyclic dependencies are a can of worms. They happen when a package A depends on a package B and vice-versa Sometime can arise through a chain of multiple packages - for example when A depends on B, which depends on C, which depends on A.

虽然循环依赖在一般的 Javascript 情况下可能工作正常(事实上,在大多数情况下 Yarn 不会就此触发警告),但只要涉及构建脚本,它们就会引起问题。实际上,为了构建包,我们首先必须确保其自身的依赖已正确构建。当两个包相互引用时,我们该怎么做?由于无法推断出要构建的第一个,这种模式将导致每个受影响包的构建脚本被忽略(并触发警告)。

¥While cyclic dependencies may work fine in the general Javascript case (and in fact Yarn won't warn you about it in most cases), they can cause issues as soon as build scripts are involved. Indeed, in order to build a package, we first must make sure that its own dependencies have been properly built. How can we do that when two packages reference each other? Since the first one to build cannot be deduced, such patterns will cause the build scripts of every affected package to simply be ignored (and a warning emitted).

网上已经有很好的文档解释了如何摆脱循环依赖,最简单的方法是将程序的共享部分提取到没有依赖的第三个包中。因此,我们描述的第一个情况将变成 A 依赖于 CB 依赖于 CC 不依赖任何东西。

¥There's already good documentation online explaining how to get rid of cyclic dependencies, the simplest one being to extract the shared part of your program into a third package without dependencies. So the first case we described would become A depends on C, B depends on C, C doesn't depend on anything.

YN0004 - DISABLED_BUILD_SCRIPTS

包有构建脚本,但它们已在整个项目中被禁用。

¥A package has build scripts, but they've been disabled across the project.

可以通过使用 enableScripts 设置全局禁用构建脚本。发生这种情况时,仍会触发警告,让你知道安装可能未完成。

¥Build scripts can be disabled on a global basis through the use of the enableScripts settings. When it happens, a warning is still emitted to let you know that the installation might not be complete.

将警告降级为通知的最安全方法是通过使用 dependenciesMeta[].built 键明确禁用受影响包的构建脚本。

¥The safest way to downgrade the warning into a notification is to explicitly disable build scripts for the affected packages through the use of the dependenciesMeta[].built key.

YN0005 - BUILD_DISABLED

包有构建脚本,但它们已通过其配置被禁用。

¥A package has build scripts, but they've been disabled through its configuration.

可以通过使用 package.json 文件中的 dependenciesMeta 设置按项目禁用构建脚本。发生这种情况时,仍会触发通知,让你知道安装可能未完成。

¥Build scripts can be disabled on a per-project basis through the use of the dependenciesMeta settings from the package.json file. When it happens, a notification is still emitted to let you know that the installation might not be complete.

YN0006 - SOFT_LINK_BUILD

包有构建脚本,但通过软链接链接。

¥A package has build scripts, but is linked through a soft link.

对于 Yarn,硬链接是指包由包管理器拥有。在这些情况下,Yarn 通常会将具有构建脚本的包复制到项目本地缓存中,以便具有多个依赖树的多个项目不会使用相同的构建工件。那么所谓的 "软链接" 有什么问题呢?

¥For Yarn, a hard link is when a package is owned by the package manager. In these instances Yarn will typically copy packages having build scripts into a project-local cache so that multiple projects with multiple dependency trees don't use the same build artifacts. So what's the problem with so-called "soft links"?

软链接是指包管理器不拥有包源。一个例子是工作区或通过 portal: 说明符引用的依赖。在这些情况下,Yarn 不能安全地假设执行构建脚本是预期的行为,因为它可能会涉及改变你的项目,或者更糟的是,改变磁盘上可能由多个项目共享的外部位置。由于 Yarn 避免做任何不安全的事情,因此它无法在软链接上运行构建脚本。

¥Soft links are when the package manager doesn't own the package source. An example is a workspace, or a dependency referenced through the portal: specifier. In these instances Yarn cannot safely assume that executing build scripts there is the intended behavior, because it would likely involve mutating your project or, even worse, an external location on your disk that might be shared by multiple projects. Since Yarn avoids doing anything unsafe, it cannot run build scripts on soft links.

有几种解决方法:

¥There are a few workarounds:

  • 使用 file: 而不是 portal: 将导致使用硬链接而不是软链接。另一方面,软件包也将被复制到缓存中,这意味着更改软件包源将需要你运行 YARN_UPDATE_FILE_CACHE=1 yarn install 才能使你的更改生效。

    ¥Using file: instead of portal: will cause a hard link to be used instead of a soft link. The other side of the coin will be that the packages will be copied into the cache as well, meaning that changing the package source will require you to run YARN_UPDATE_FILE_CACHE=1 yarn install for your changes to be taken into account.

  • 你可以从受影响包的目录中手动运行 yarn run postinstall(或任何名为构建脚本的名称)。这需要你知道必须以什么顺序调用它们,但通常是最安全的选择。

    ¥You can manually run yarn run postinstall (or whatever is named your build script) from the directory of the affected packages. This requires you to know in which order they'll have to be called, but is generally the safest option.

  • 你可以简单地放弃使用带有软链接的构建脚本。虽然这个建议看起来像是 "通过不遇到问题来解决问题" 的一个坏例子,但请考虑从开发者体验的角度来看,开发中的构建脚本可能不是最好的效果 - 它们通常意味着你需要运行脚本才能看到你的更改,而这通常不是你想要的。

    ¥You can simply abstain from using build scripts with soft links. While this suggestion might seem like a bad case of "fix a problem by not encountering the problem", consider that build scripts in development might not be of the best effect from a developer experience perspective - they usually mean that you'll need to run a script before being able to see your changes, which is often not what you seek.

YN0007 - MUST_BUILD

必须构建包。

¥A package must be built.

当 Yarn 希望让你知道需要构建一个包才能完成安装时,会出现此信息性消息。这通常只发生在两种情况下:要么包从未被构建过,要么其先前的构建失败(返回非零退出代码)。

¥This informational message occurs when Yarn wishes to let you know that a package will need to be built for the installation to complete. This usually occurs in only two cases: either the package never has been built before, or its previous build failed (returned a non-zero exit code).

YN0008 - MUST_REBUILD

必须重建包。

¥A package must be rebuilt.

当 Yarn 希望让你知道需要重建包才能完成安装时,会出现此信息消息。这通常发生在一种情况下:当包的依赖树发生变化时。请注意,这还包括其传递依赖,有时可能会导致意外的重建(例如,如果 A 依赖于依赖于 C@1B,并且如果 Yarn 出于某种原因决定 C 应该被提升到 C@2,那么 A 将需要重建)。

¥This information message occurs when Yarn wishes to let you know that a package will need to be rebuilt in order for the installation to complete. This usually occurs in a single case: when the package's dependency tree has changed. Note that this also includes its transitive dependencies, which sometimes may cause surprising rebuilds (for example, if A depends on B that depends on C@1, and if Yarn decides for some reason that C should be bumped to C@2, then A will need to be rebuilt).

YN0009 - BUILD_FAILED

包构建失败。

¥A package build failed.

这个问题通常不是来自 Yarn 本身,只是意味着描述为具有构建指令的包无法成功构建。

¥This problem typically doesn't come from Yarn itself, and simply means that a package described as having build directives couldn't get built successfully.

要查看实际的错误消息,请阅读报告中链接的文件。它将包含失败脚本的完整输出。

¥To see the actual error message, read the file linked in the report. It will contain the full output of the failing script.

YN0010 - RESOLVER_NOT_FOUND

无法找到给定包的解析器。

¥A resolver cannot be found for the given package.

解析器是负责将范围(^1.0.0)转换为引用(1.2.3)的组件。它们各自包含自己的逻辑来执行此操作 - semver 解析器是最著名的,但远非唯一。GitHub 解析器将 GitHub 存储库转换为 tarball url,Git 解析器规范化发送到 git 的路径,...每个解析器负责不同的解析策略。缺少解析器意味着缺少其中一个策略。

¥Resolvers are the components tasked from converting ranges (^1.0.0) into references (1.2.3). They each contain their own logic to do so - the semver resolver is the most famous one but far from being the only one. The GitHub resolver transforms GitHub repositories into tarball urls, the Git resolver normalizes the paths sent to git, ... each resolver takes care of a different resolution strategy. A missing resolver means that one of those strategies is missing.

此错误通常是由于缺少 Yarn 插件引起的。

¥This error is usually caused by a Yarn plugin being missing.

YN0011 - FETCHER_NOT_FOUND

无法找到给定包的获取器。

¥A fetcher cannot be found for the given package.

获取器是获取引用并从远程位置获取源代码的组件。semver 获取器可能会从某个注​​册表中获取包,而工作区获取器只会重定向到磁盘上可以找到源的位置。

¥Fetchers are the components that take references and fetch the source code from the remote location. A semver fetcher would likely fetch the packages from some registry, while a workspace fetcher would simply redirect to the location on the disk where the sources can be found.

此错误通常是由于缺少 Yarn 插件引起的。

¥This error is usually caused by a Yarn plugin being missing.

YN0012 - LINKER_NOT_FOUND

无法找到给定包的链接器。

¥A linker cannot be found for the given package.

链接器是负责从获取器返回的工件中提取源并以目标环境可以理解的方式将它们放在磁盘上的组件。Node 链接器将使用 Plug'n'Play 策略,而 PHP 链接器将使用自动加载策略。

¥Linkers are the components tasked from extracting the sources from the artifacts returned by the fetchers and putting them on the disk in a manner that can be understood by the target environment. The Node linker would use the Plug'n'Play strategy, while a PHP linker would use an autoload strategy instead.

此错误通常是由于缺少 Yarn 插件引起的。

¥This error is usually caused by a Yarn plugin being missing.

YN0013 - FETCH_NOT_CACHED

无法在给定包的缓存中找到包,将从其远程位置获取。

¥A package cannot be found in the cache for the given package and will be fetched from its remote location.

当从远程位置下载包时,Yarn 将其存储在名为 cache 的特定文件夹中。然后,下次下载此包时,Yarn 只需检查此目录并使用存储的包(如果可用)。此消息仅表示无法在那里找到包。这不是一个大问题,但你可能应该尽可能地限制它 - 例如通过使用 零安装

¥When a package is downloaded from whatever its remote location is, Yarn stores it in a specific folder called then cache. Then, the next time this package was to be downloaded, Yarn simply check this directory and use the stored package if available. This message simply means that the package couldn't be found there. It's not a huge issue, but you probably should try to limit it as much as possible - for example by using Zero-Installs.

YN0014 - YARN_IMPORT_FAILED

无法从 v1 锁文件正确导入锁文件。

¥A lockfile couldn't be properly imported from a v1 lockfile.

v2 版本包含 Yarn 设计方式的重大变化,锁文件格式就是其中之一。在极少数情况下,v1 锁定文件中包含的数据与我们存储在 v2 文件中的数据不兼容。发生这种情况时,Yarn 将触发此警告并再次解析包描述符。只有这个包会受到影响;所有其他版本将继续按预期导入。

¥The v2 release contains major changes in the way Yarn is designed, and the lockfile format is one of them. In some rare cases, the data contained in the v1 lockfile aren't compatible with the ones we stored within the v2 files. When it happens, Yarn will emit this warning and resolve the package descriptor again. Only this package will be affected; all others will continue to be imported as expected.

YN0015 - REMOTE_INVALID

远程源返回了无效数据。

¥The remote source returned invalid data.

当解析器和获取器与之通信的远程源返回的值与我们预期的不一致时(例如,因为它们缺少字段),解析器和获取器会抛出此错误。

¥This error is thrown by the resolvers and fetchers when the remote sources they communicate with return values that aren't consistent with what we would expect (for example because they are missing fields).

YN0016 - REMOTE_NOT_FOUND

远程源返回了有效数据,但告诉我们找不到包。

¥The remote source returned valid data, but told us the package couldn't be found.

当解析器和获取器与之通信的远程源通知它们请求的包不存在时,解析器和获取器会抛出此错误。如果包已取消发布,并且 Yarn 通常无能为力,则可能会发生这种情况。

¥This error is thrown by the resolvers and fetchers when the remote sources they communicate with inform them that the package against which have been made the request doesn't exist. This might happen if the package has been unpublished, and there's usually nothing Yarn can do.

YN0017 - RESOLUTION_PACK

此错误代码目前未使用(它用于打印参与解析算法每次传递的包的数量,但与其实用性相比,它被认为过于冗长)。

¥This error code isn't used at the moment (it used to print the number of packages that took part in each pass of the resolution algorithm, but was deemed too verbose compared to its usefulness).

YN0018 - CACHE_CHECKSUM_MISMATCH

来自缓存的包的校验和与锁定文件的期望不匹配。

¥The checksum of a package from the cache doesn't match what the lockfile expects.

这种情况通常发生在你通过编辑缓存中包含的文件以进行调试来修改缓存中的 zip 存档之后。使用以下三个命令之一来绕过它:

¥This situation usually happens after you've modified the zip archives from your cache by editing the files it contains for debug purposes. Use one of the three following commands in order to bypass it:

  • YARN_CHECKSUM_BEHAVIOR=reset 将从缓存中删除文件并再次下载

    ¥YARN_CHECKSUM_BEHAVIOR=reset will remove the files from the cache and download them again

  • YARN_CHECKSUM_BEHAVIOR=update 将更新锁定文件以包含新的校验和

    ¥YARN_CHECKSUM_BEHAVIOR=update will update the lockfile to contain the new checksum

  • YARN_CHECKSUM_BEHAVIOR=ignore 将使用现有文件但不会更新锁定文件

    ¥YARN_CHECKSUM_BEHAVIOR=ignore will use the existing files but won't update the lockfile

YN0019 - UNUSED_CACHE_ENTRY

安装依赖时检测到缓存中的文件未使用。

¥A file from the cache has been detected unused while installing dependencies.

运行 yarn cache clean 将导致 Yarn 删除 .yarn/cache 内的所有内容。

¥Running yarn cache clean will cause Yarn to remove everything inside .yarn/cache.

YN0020 - MISSING_LOCKFILE_ENTRY

无法在锁定文件中找到包描述符。

¥A package descriptor cannot be found in the lockfile.

许多命令(例如 yarn run)要求锁文件处于与当前项目一致的状态才能正常运行。当 Yarn 检测到你的项目引用了未在锁定文件中列出的包时,将生成此错误(通常是因为你在未运行 yarn install 的情况下修改了 dependencies 字段,或者因为你添加了新的工作区)。运行 yarn install 几乎肯定会修复这个特定的错误。

¥A lot of commands (for example yarn run) require the lockfile to be in a state consistent with the current project in order to behave properly. This error will be generated when Yarn detects that your project references a package that isn't listed within the lockfile (usually because you modified a dependencies field without running yarn install, or because you added a new workspace). Running yarn install will almost certainly fix this particular error.

YN0021 - WORKSPACE_NOT_FOUND

依赖使用无法解析为现有工作区的 workspace: 范围。

¥A dependency uses a workspace: range that cannot be resolved to an existing workspace.

workspace: 协议是 Yarn v2 中出现的一项新功能,它允许以当前项目的特定工作区为目标,而无需冒着在工作区不存在的情况下从其他来源提取数据的风险。此错误恰恰意味着工作区由于错误消息中描述的原因而不存在。

¥The workspace: protocol is a new feature that appeared in Yarn v2 that allows to target a specific workspace of the current project without risking to ever pull data from other sources in case the workspace doesn't exist. This error precisely means that the workspace doesn't exist for the reason described in the error message.

YN0022 - TOO_MANY_MATCHING_WORKSPACES

此错误应被视为过时且不存在;如果有,请打开一个问题。

¥This error should be considered obsolete and not exist; open an issue if you have it.

YN0023 - CONSTRAINTS_MISSING_DEPENDENCY

你的一个工作区应该依赖于依赖,但实际上却没有。

¥One of your workspaces should depend on a dependency but doesn't.

constraint 已生效,声明指定的工作区必须依赖于指定依赖的指定范围。由于目前没有,Yarn 在运行 yarn constraints 时会触发此错误。为了修复它,只需运行 yarn constraints --fix,它将自动修复所有此类错误。

¥A constraint has been put into effect that declares that the specified workspace must depend on the specified range of the specified dependency. Since it currently doesn't, Yarn emits this error when running yarn constraints. In order to fix it simply run yarn constraints --fix which will autofix all such errors.

YN0024 - CONSTRAINTS_INCOMPATIBLE_DEPENDENCY

你的一个工作区应该依赖于依赖的特定版本,但实际上却没有。

¥One of your workspaces should depend on a specific version of a dependency but doesn't.

constraint 已生效,声明指定的工作区必须依赖于指定依赖的指定范围。由于目前没有,Yarn 在运行 yarn constraints 时会触发此错误。为了修复它,只需运行 yarn constraints --fix,它将自动修复所有此类错误。

¥A constraint has been put into effect that declares that the specified workspace must depend on the specified range of the specified dependency. Since it currently doesn't, Yarn emits this error when running yarn constraints. In order to fix it simply run yarn constraints --fix which will autofix all such errors.

YN0025 - CONSTRAINTS_EXTRANEOUS_DEPENDENCY

你的一个工作区不应该依赖于它列出的依赖之一。

¥One of your workspaces shouldn't depend on one of the dependencies it lists.

constraint 已生效,声明指定的工作区必须依赖于指定依赖的指定范围。由于目前没有,Yarn 在运行 yarn constraints 时会触发此错误。为了修复它,只需运行 yarn constraints --fix,它将自动修复所有此类错误。

¥A constraint has been put into effect that declares that the specified workspace must depend on the specified range of the specified dependency. Since it currently doesn't, Yarn emits this error when running yarn constraints. In order to fix it simply run yarn constraints --fix which will autofix all such errors.

YN0026 - CONSTRAINTS_INVALID_DEPENDENCY

你的一个工作区列出了无效的依赖。

¥One of your workspaces lists an invalid dependency.

constraint 已生效,声明指定的工作区在当前状态下可能不应该依赖于指定的依赖。由于目前确实如此,Yarn 在运行 yarn constraints 时会触发此错误。修复此错误需要手动干预,因为从 Yarn 的角度来看修复是不明确的。

¥A constraint has been put into effect that declares that the specified workspace probably shouldn't depend on the specified dependency in its current state. Since it currently does, Yarn emits this error when running yarn constraints. Fixing this error require manual intervention as the fix is ambiguous from Yarn's point of view.

YN0027 - CANT_SUGGEST_RESOLUTIONS

Yarn 无法为你添加到项目中的包找出适当的范围建议。

¥Yarn cannot figure out proper range suggestions for the packages you're adding to your project.

运行 yarn add 时,如果未向要添加的包添加明确的范围,Yarn 将尝试查找符合你意图的版本。通常,这意味着它将优先选择项目工作区,如果找不到任何工作区,它将尝试查询 npm 注册表以获取已发布版本的列表,并使用最高的版本。此错误意味着此过程失败,Yarn 无法成功确定应将哪个版本的包添加到你的项目中。

¥When running yarn add without adding explicit ranges to the packages to add, Yarn will try to find versions that match your intent. Generally it means that it will prefer project workspaces and, if it cannot find any, will instead try to query the npm registry for the list of published releases and use whatever is the highest one. This error means that this process failed and Yarn cannot successfully figure out which version of the package should be added to your project.

YN0028 - FROZEN_LOCKFILE_EXCEPTION

如果 Yarn 要完成安装,你的锁定文件将被修改。

¥Your lockfile would be modified if Yarn was to finish the install.

--immutable 选项传递给 yarn install 时,Yarn 将确保锁文件在此过程中不会被修改,如果发生这种情况,则会抛出异常(例如,如果锁文件中缺少新添加的包,或者当前 Yarn 版本需要某种迁移才能使用锁文件)。

¥When passing the --immutable option to yarn install, Yarn will ensure that the lockfile isn't modified in the process and will instead throw an exception if this situation was to happen (for example if a newly added package was missing from the lockfile, or if the current Yarn release required some kind of migration before being able to work with the lockfile).

此选项通常用于你的 CI 和生产服务器,修复此错误只需在你的本地开发环境中运行 yarn install 并提交包含更新的锁定文件的 PR 即可。

¥This option is typically meant to be used on your CI and production servers, and fixing this error should simply be a matter of running yarn install on your local development environment and submitting a PR containing the updated lockfile.

YN0029 - CROSS_DRIVE_VIRTUAL_LOCAL

已删除:虚拟不再使用符号链接实现。

¥Removed: Virtuals aren't implemented using symlinks anymore.

YN0030 - FETCH_FAILED

此错误代码目前未使用;我们理想情况下想解释为什么获取失败,而不是。

¥This error code isn't used at the moment; we ideally want to explain why did the fetch fail rather than .

YN0031 - DANGEROUS_NODE_MODULES

Yarn 正在使用 Plug'n'Play 安装包,但发现了一个 node_modules 文件夹。

¥Yarn is installing packages using Plug'n'Play, but a node_modules folder has been found.

当检测到你的项目包含实际上似乎包含包的 node_modules 文件夹时,会触发此警告。不建议这样做,因为它们可能是你以前使用的任何包管理器的遗留,可能会混淆你的工具并导致你陷入 "在我的计算机上有效" 情况。

¥This warning is emitted when your project is detected as containing node_modules folders that actually seem to contain packages. This is not advised as they're likely relicts of whatever package manager you used before, and might confuse your tools and lead you into "works on my machine" situations.

YN0032 - NODE_GYP_INJECTED

在某些情况下,Yarn 可能会检测到包需要 node-gyp,而此包并未明确列出依赖。此行为是出于遗留原因,不应依赖此行为,原因如下:

¥In some situation Yarn might detect that node-gyp is required by a package without this package explicitly listing the dependency. This behavior is there for legacy reason and should not be relied upon for the following reasons:

  • 检测是否隐式需要 node-gyp 的主要方法是检查包是否包含 bindings.gyp 文件。但是,执行此检查意味着在 Yarn 解析依赖树时已知包列表。这需要获取所有 npm 档案作为解决步骤的一部分(而不是等到专用的获取步骤),而所有这些都只是为了这个有问题的功能。

    ¥The main way to detect whether node-gyp is implicitly required is to check whether the package contains a bindings.gyp file. However, doing this check implies that the package listing is known at the time Yarn resolves the dependency tree. This would require to fetch all npm archives as part of the resolution step (rather than wait until the dedicated fetch step), and all that just for the sake of this problematic feature.

  • node-gyp 的隐式依赖不会向包管理器提供任何提示,说明哪些版本的 node-gyp 与正在构建的包兼容。Yarn 尽最大努力在 npm:* 上添加隐式依赖,但这可能是错误的,我们无法知道它 - 使用不兼容的版本编译时,你的安装将意外崩溃。

    ¥Implicit dependencies on node-gyp don't provide any hint to the package manager as to which versions of node-gyp are compatible with the package being built. Yarn does its best by adding an implicit dependency on npm:*, but it might be wrong and we'll have no way to know it - your installs will just crash unexpectedly when compiled with incompatible versions.

省略 node-gyp 的包通常这样做是为了在不需要构建包(预构建二进制文件)时减少最终依赖树中的包数量。虽然这是一个合理的愿望,但这样做违反了包管理器规则,我们更愿意通过专用功能而不是通过此类黑客来解决这个问题。同时,我们强烈建议尽可能考虑通过 WebAssembly 预构建原生依赖 - 然后 node-gyp 问题完全消失。

¥Packages omitting node-gyp usually do so in order to decrease the amount of packages in the final dependency tree when building the package isn't required (prebuilt binaries). While a reasonable wish, doing this goes against the package manager rules and we would prefer to solve this through a dedicated feature rather than through such hacks. In the meantime we strongly recommend to consider prebuilding native dependencies via WebAssembly if possible - then the node-gyp problem completely disappears.

YN0046 - AUTOMERGE_FAILED_TO_PARSE

当在 yarn.lock 文件中发现 Git 冲突标记并且无法解析一个或两个单个候选锁定文件时,会触发此错误。这通常是由于以下两种情况之一而发生的:

¥This error is triggered when Git conflict tokens are found within the yarn.lock file and one or both of the individual candidate lockfiles cannot be parsed. This typically happens because of one of those two situations:

  • 如果你正在使用 Yarn v2 处理分支并尝试使用 Yarn v1 合并分支,则会触发此错误(v1 锁定文件不是 Yaml,这会阻止它们被解析。即使我们可以,与 v2 锁定文件相比,它们也不包含足够的信息)。

    ¥If you're working on a branch with Yarn v2 and are trying to merge a branch using Yarn v1, this error will be triggered (the v1 lockfiles aren't Yaml, which prevents them from being parsed. Even if we could, they don't contain enough information compared to the v2 lockfiles).

    • 修复此问题的最简单方法是使用 git checkout --theirs yarn.lock,然后再次跟进 yarn install(可以跟进 yarn cache clean 以删除不再需要的任何文件)。这将导致重新导入 v1 锁定文件。v2 解析将丢失,但 Yarn 会检测到它并重新解决它们。

      ¥The easiest way to fix it is to use git checkout --theirs yarn.lock, and follow up with yarn install again (which can be followup by yarn cache clean to remove any file that wouldn't be needed anymore). This will cause the v1 lockfile to be re-imported. The v2 resolutions will be lost, but Yarn will detect it and resolve them all over again.

  • 如果你有多个级别的冲突。Yarn 不支持此类冲突,你必须想办法只有两个级别。这通常是通过首先解决两个分支之间的冲突,然后在上一步和第三个分支的合并结果上再次解决它们来完成的。

    ¥If you have multiple levels of conflicts. Yarn doesn't support such conflicts, and you'll have to figure out a way to only have two levels. This is typically done by first resolving the conflicts between two branches, and then resolving them again on the merge result of the previous step and the third branch.

YN0047 - AUTOMERGE_IMMUTABLE

当 Yarn 在不可变模式 (yarn install --immutable) 下执行时,在 yarn.lock 文件中发现 Git 冲突标记时,会触发此错误。

¥This error is triggered when Git conflict tokens are found within the yarn.lock file while Yarn is executing under the immutable mode (yarn install --immutable).

在此模式下,Yarn 不允许编辑任何文件,甚至不允许自动解决冲突。此模式通常用于 CI,以确保你的项目在合并到主干之前始终处于正确状态。

¥When under this mode, Yarn isn't allowed to edit any file, not even for automatically resolving conflicts. This mode is typically used on CI to ensure that your projects are always in a correct state before being merged into the trunk.

为了解决这个问题,请尝试在你的计算机上再次运行没有 --immutable 标志的 yarn install,然后如果命令成功,则提交更改。

¥In order to solve this problem, try running yarn install again on your computer without the --immutable flag, then commit the changes if the command succeeded.

YN0048 - AUTOMERGE_SUCCESS

当在 yarn.lock 文件中发现 Git 冲突标记但被 Yarn 自动修复时,会触发此信息性消息。没有其他事情可做,一切都应该开箱即用!

¥This informational message is emitted when Git conflict tokens were found within the yarn.lock file but were automatically fixed by Yarn. There's nothing else to do, everything should work out of the box!

YN0049 - AUTOMERGE_REQUIRED

当在 yarn.lock 文件中发现 Git 冲突标记时,会触发此信息性消息。然后,Yarn 将尝试按照其内部启发式方法自动解决冲突。

¥This informational message is emitted when Git conflict tokens are found within the yarn.lock file. Yarn will then try to automatically resolve the conflict by following its internal heuristic.

自动合并逻辑非常简单:它将从拉取的分支中获取锁文件,通过添加本地分支中的信息对其进行修改,然后再次运行 yarn install 以修复在此过程中可能丢失的任何内容。

¥The automerge logic is pretty simple: it will take the lockfile from the pulled branch, modify it by adding the information from the local branch, and run yarn install again to fix anything that might have been lost in the process.

YN0050 - DEPRECATED_CLI_SETTINGS

当通过其参数将选项传递给 CLI 命令(例如 --cache-folder)时,会触发此错误。

¥This error is triggered when passing options to a CLI command through its arguments (for example --cache-folder).

从 v2 开始,不再支持此功能。原因是我们将所有配置整合到一个可以从 yarnrc 文件中定义的存储中。这可确保你的所有命令都在相同的环境中运行(以前并非如此,这取决于你是否在所有命令上使用 --cache-folder 或仅在安装中使用)。CLI 选项现在将仅用于控制特定命令(如 --verbose)的一次性行为。

¥Starting from the v2, this isn't supported anymore. The reason for this is that we've consolidated all of our configuration inside a single store that can be defined from a yarnrc file. This guarantees that all your commands run inside the same environments (which previously wasn't the case depending on whether you were using --cache-folder on all your commands or just the install). CLI options will now only be used to control the one-time-behaviors of a particular command (like --verbose).

Netlify 用户特别说明:Netlify 当前将 自动通过 --cache-folder 选项设置为 Yarn,你无法禁用它。因此,当我们检测到 Yarn 在 Netlify 上运行时,我们决定将其设为警告而不是错误(我们仍然忽略该标志)。我们建议在他们的存储库上对 相关问题 点赞,因为我们可能会在未来的主要版本中删除这个特殊情况。

¥Special note for Netlify users: Netlify currently automatically passes the --cache-folder option to Yarn, and you cannot disable it. For this reason we decided to make it a warning rather than an error when we detect that Yarn is running on Netlify (we still ignore the flag). We suggest upvoting the relevant issue on their repository, as we're likely to remove this special case in a future major release.

YN0059 - INVALID_RANGE_PEER_DEPENDENCY

包请求对等依赖,但提供的范围不是有效的 semver 范围。无法确保提供的包满足对等依赖请求。必须修复范围才能消除警告。这不会阻止解决,但可能会使系统处于不正确的状态。

¥A package requests a peer dependency, but the range provided is not a valid semver range. It is not possible to ensure the provided package meets the peer dependency request. The range must be fixed in order for the warning to go away. This will not prevent resolution, but may leave the system in an incorrect state.

YN0060 - INCOMPATIBLE_PEER_DEPENDENCY

包请求对等依赖,但依赖树中的父级提供的版本不满足对等依赖的范围。应更改父级以提供有效版本或更新对等依赖范围。这不会阻止解决,但可能会使系统处于不正确的状态。

¥A package requests a peer dependency, but its parent in the dependency tree provides a version that does not satisfy the peer dependency's range. The parent should be altered to provide a valid version or the peer dependency range updated. This will not prevent resolution, but may leave the system in an incorrect state.

YN0061 - DEPRECATED_PACKAGE

包被发布者标记为已弃用。避免使用它,而是使用弃用消息中提供的替代方案。

¥A package is marked as deprecated by the publisher. Avoid using it, use the alternative provided in the deprecation message instead.

YN0062 - INCOMPATIBLE_OS

已删除:由 INCOMPATIBLE_ARCHITECTURE 替换。

¥Removed: Replaced by INCOMPATIBLE_ARCHITECTURE.

YN0063 - INCOMPATIBLE_CPU

已删除:由 INCOMPATIBLE_ARCHITECTURE 替换。

¥Removed: Replaced by INCOMPATIBLE_ARCHITECTURE.

YN0068 - UNUSED_PACKAGE_EXTENSION

Yarn 检测到 packageExtension 未使用,这意味着选择器与任何已安装的包都不匹配。

¥A packageExtension is detected by Yarn as being unused, which means that the selector doesn't match any of the installed packages.

YN0069 - REDUNDANT_PACKAGE_EXTENSION

Yarn 检测到 packageExtension 是不需要的,这意味着所选包在有和没有扩展的情况下具有相同的行为。

¥A packageExtension is detected by Yarn as being unneeded, which means that the selected packages have the same behavior with and without the extension.

无法安装外部软链接(门户),因为父包中存在不兼容版本的依赖。这可以防止门户表示 node_modules 安装,而无需将文件写入门户的目标目录,出于安全原因,这是被禁止的。

¥An external soft link (portal) cannot be installed, because incompatible version of a dependency exists in the parent package. This prevents portal representation for node_modules installs without a need to write files into portal's target directory, which is forbidden for security reasons.

解决方法 如果门户目标和门户父级之间冲突依赖的范围重叠,则解决方法是使用 yarn dedupe foo(其中 foo 是冲突依赖名称)将冲突依赖升级到最高可用版本,如果使用 yarn dedupe 而不带参数,则项目中的所有依赖都将升级到 package.json 中其范围内的最高版本。另一种选择是使用 link: 协议而不是 portal:,并明确在目标目录中安装依赖。

¥Workarounds If the ranges for conflicting dependencies overlap between portal target and portal parent, the workaround is to use yarn dedupe foo (where foo is the conflicting dependency name) to upgrade the conflicting dependencies to the highest available versions, if yarn dedupe is used without arguments, all the dependencies across the project will be upgraded to the highest versions within their ranges in package.json. Another alternative is to use link: protocol instead of portal: and install dependencies inside the target directory explicitly.

YN0072 - NM_PRESERVE_SYMLINKS_REQUIRED

项目中使用具有子依赖的门户依赖。--preserve-symlinks 必须使用节点选项来启动应用,以便门户依赖找到其子依赖和对等依赖。

¥A portal dependency with subdependencies is used in the project. --preserve-symlinks Node option must be used to start the application in order for portal dependency to find its subdependencies and peer dependencies.

YN0074 - NM_HARDLINKS_MODE_DOWNGRADED

由于全局缓存和安装文件夹位于不同的设备上,nmMode 已降级为 hardlinks-local。如果希望 hardlinks-global 生效,请考虑更改 globalFolder 设置并将全局缓存放在与项目相同的设备上。

¥nmMode has been downgraded to hardlinks-local due to global cache and install folder being on different devices. Consider changing globalFolder setting and place the global cache on the same device as your project, if you want hardlinks-global to take effect.

YN0075 - PROLOG_INSTANTIATION_ERROR

当使用无效签名调用 Prolog 谓词时,会出现此错误。具体来说,这意味着某些谓词参数未实例化(即没有定义的值),而谓词需要某些参数。这并不意味着你需要对值进行硬编码,只是需要在调用谓词之前分配一个值。对于大多数 Yarn 谓词中的 WorkspaceCwd 参数,这意味着不是调用:

¥This error appears when a Prolog predicate is called with an invalid signature. Specifically, it means that some of the predicate parameters are non-instantiated (ie have no defined value), when the predicate would expect some. This doesn't mean that you need to hardcode a value, just that you need to assign one before calling the predicate. In the case of the WorkspaceCwd parameter from most of the Yarn predicates, it means that instead of calling:

workspace_field(WorkspaceCwd, 'name', _).

你还可以使用 workspace/1 谓词让 Prolog "fill" 在 workspace_field/3 中使用它之前使用 WorkspaceCwd 参数:

¥You would also use the workspace/1 predicate to let Prolog "fill" the WorkspaceCwd parameter prior to using it in workspace_field/3:

workspace(WorkspaceCwd), workspace_field(WorkspaceCwd, 'name', _).

有关调用错误消息报告的谓词时必须实例化的参数的更多信息,请参阅我们文档中的 专用页面

¥For more information about the parameters that must be instantiated when calling the predicate reported by the error message, consult the dedicated page from our documentation.

YN0076 - INCOMPATIBLE_ARCHITECTURE

包在其清单中指定(通过 os / cpu / libc 字段)与系统架构不兼容。它不会被获取、链接,并且其安装后脚本不会在此系统上运行。

¥A package is specified in its manifest (through the os / cpu / libc fields) as being incompatible with the system architecture. It will not be fetched, linked, and its postinstall scripts will not run on this system.

YN0077 - GHOST_ARCHITECTURE

如果某些原生包表示它们不支持项目所针对的系统,则可能会将其排除在安装之外。此检测通常基于你当前的系统参数,但可以使用 supportedArchitectures 配置选项 进行配置。如果你的操作系统或 CPU 不在此列表中,Yarn 将跳过这些包并触发警告。

¥Some native packages may be excluded from the install if they signal they don't support the systems the project is intended for. This detection is typically based on your current system parameters, but it can be configured using the supportedArchitectures config option. If your os or cpu are missing from this list, Yarn will skip the packages and raise a warning.

请注意,supportedArchitectures 中的所有字段都默认为 current,这是一个取决于你本地参数的动态值。例如,如果你希望支持 "我当前的操作系统,无论它是什么,加上 linux",可以将 supportedArchitectures.os 设置为 ["current", "linux"]

¥Note that all fields from supportedArchitectures default to current, which is a dynamic value depending on your local parameters. For instance, if you wish to support "my current os, whatever it is, plus linux", you can set supportedArchitectures.os to ["current", "linux"].

YN0078 - RESOLUTION_MISMATCH

从 Yarn 4 开始,当 Yarn 检测到当前环境是拉取请求时,它将自动在 CI 上启用 --check-resolutions 标志。在此模式下,Yarn 将检查锁文件解析是否与初始范围一致。例如,给定初始依赖 foo@npm:^1.0.0

¥Starting from Yarn 4, Yarn will automatically enable the --check-resolutions flag on CI when it detects the current environment is a pull request. Under this mode, Yarn will check that the lockfile resolutions are consistent with what the initial range is. For example, given an initial dependency of foo@npm:^1.0.0:

  • foo@npm:1.2.0 是有效的解析

    ¥foo@npm:1.2.0 is a valid resolution

  • foo@npm:2.0.0 不是有效的解析,因为它与预期的 semver 范围不匹配

    ¥foo@npm:2.0.0 isn't a valid resolution, because it doesn't match the expected semver range

  • bar@npm:1.2.0 也不是有效的解析,因为名称不匹配

    ¥bar@npm:1.2.0 isn't a valid resolution either, because the name doesn't match

在正常情况下,此错误永远不会触发,因为 Yarn 应该始终根据依赖生成令人满意的解决方案。如果你仍然遇到它,则可能是以下两种情况之一:

¥This error should never trigger under normal circumstances, as Yarn should always generate satisfying resolutions given a dependency. If you hit it nonetheless, it may be either of two things:

  • Yarn 有一个错误。可能会发生!检查不匹配情况以确保无误,如果你有疑问,请在 Discord 上 ping 我们,我们会告诉你是否需要担心(在此之前,请快速查看我们的 存储库问题,以防有人报告相同的行为)。

    ¥Yarn has a bug. It may happen! Review the mismatch to be sure and, in case you have a doubt, ping us on Discord and we'll tell you whether it's something to worry about (before doing that, take a quick look at our repository issues in case someone reported the same behaviour).

  • 或者你可能有人在你的锁文件上做了奇怪的事情。这可能是一个错误(例如,有人手动修改了用于调试的锁定文件,但忘记恢复更改),也可能是一个问题(例如,恶意用户试图执行某种 供应链攻击)。

    ¥Or you might have someone doing strange things on your lockfile. It might be a mistake (for example someone manually modifying a lockfile for debug but forgetting to revert the changes), or a problem (for example a malicious users trying to perform some sort of supply chain attack).

如果用例看起来合法(例如,如果错误来自 Yarn),你可以通过在 yarn install 命令中添加 --no-check-resolutions 标志来绕过对 PR 的检查。但要小心:这是一个安全功能;禁用它可能会产生后果。

¥If the use case appears legit (for example if the bug comes from Yarn), you can bypass the check on PRs by adding a --no-check-resolutions flag to your yarn install command. But be careful: this is a security feature; disabling it may have consequences.

YN0080 - NETWORK_DISABLED

enableNetwork 标志设置为 false,阻止触发任何请求。

¥The enableNetwork flag is set to false, preventing any request to be made.

请注意,Yarn 配置允许通过 npmRegistries 基于每个注册表设置 enableNetwork

¥Note that the Yarn configuration allows enableNetwork to be set on a per-registry basis via npmRegistries.

YN0081 - NETWORK_UNSAFE_HTTP

Yarn 默认拒绝执行 http(非 https)查询,以保护你免受意外的中间人攻击。

¥Yarn will by default refuse to perform http (non-https) queries to protect you against accidental man-in-the-middle attacks.

要绕过此保护,请将指定的主机名添加到 unsafeHttpWhitelist

¥To bypass this protection, add the specified hostname to unsafeHttpWhitelist.

YN0082 - RESOLUTION_FAILED

Yarn 无法找到可以满足请求范围的软件包版本。这通常发生在针对尚未发布的版本的 semver 范围中(例如,当最新版本为 0.9.0 时为 ^1.0.0),但也可能由其他几个原因引起:

¥Yarn failed to locate a package version that could satisfy the requested range. This usually happens with semver ranges that target versions not published yet (for example ^1.0.0 when the latest version is 0.9.0), but can be also caused by a couple of other reasons:

  • 注册表可能未正确设置(因此 Yarn 查询公共 npm 注册表而不是内部注册表)

    ¥The registry may not have been set properly (so Yarn is querying the public npm registry instead of your internal one)

  • 版本可能尚未发布(尽管这对于公共注册表来说是不可能的)

    ¥The version may have been unpublished (although this shouldn't be possible for the public registry)

YN0083 - AUTOMERGE_GIT_ERROR

当自动修复合并冲突时,Yarn 需要知道必须合并在一起的两个锁文件版本是什么。为此,它将根据情况运行 git rev-parse MERGE_HEAD HEAD 和/或 git rev-parse REBASE_HEAD HEAD。如果这两个命令都失败,则合并无法成功。

¥When autofixing merge conflicts, Yarn needs to know what are the two lockfile versions it must merge together. To do that, it'll run git rev-parse MERGE_HEAD HEAD and/or git rev-parse REBASE_HEAD HEAD, depending on the situation. If both of those commands fail, the merge cannot succeed.

如果有人意外提交了锁文件而没有先解决合并冲突,则可能会发生这种情况 - 如果发生这种情况,你需要将锁文件恢复为早期的工作版本并运行 yarn install

¥This may happen if someone accidentally committed the lockfile without first resolving the merge conflicts - should that happen, you'll need to revert the lockfile to an earlier working version and run yarn install.

YN0085 - UPDATED_RESOLUTION_RECORD

当在项目中添加或删除锁文件条目时,会打印此消息。

¥This message is printed when a lockfile entry is added or removed from a project.

YN0086 - EXPLAIN_PEER_DEPENDENCIES_CTA

对等依赖有点复杂,调试它们可能需要大量信息。由于 Yarn 尽力将消息保持在一行上,因此我们提供了一个 yarn explain peer-requirements 命令,该命令比我们在常规安装中显示的命令更详细。

¥Peer dependencies are a little complex, and debugging them may require a lot of information. Since Yarn tries its best to keep messages on a single line, we provide a yarn explain peer-requirements command that goes into much more details than what we show on regular installs.

要使用它,只需将原始对等解析错误消息中提供的 p 前缀代码传递给它:

¥To use it, simply pass it the p-prefixed code provided in the original peer resolution error message:

YN0087 - MIGRATION_SUCCESS

从主要版本迁移到下一个版本时,某些默认值可能会发生变化。在这种情况下,Yarn 将尝试通过将其值固定在你的配置设置中来暂时保留旧的默认值。

¥When migrating from a major version to the next, some default values may change. When that's the case, Yarn will attempt to temporarily keep the old default by pinning their values in your configuration settings.

要查看此消息出现时应用的确切更改,请检查 .yarnrc.yml 文件的内容以及存储库签出中可能显示已修改的任何其他文件。

¥To see the exact changes applied when this message appears, check the content of the .yarnrc.yml file and any other file that may appear modified in your repository checkout.

YN0088 - VERSION_NOTICE

在本地机器上,Yarn 将定期检查是否有新版本可用。如果是,则将打印一次信息消息,然后静音直到第二天。

¥On local machines, Yarn will periodically check whether new versions are available. Should one be, an informational message will be printed once, then silenced until the next day.

如果不想升级,则无需升级 - 但保持 Yarn 最新通常是一个好主意,因为它们往往伴随着大量的性能改进、错误修复和新功能。

¥You don't have to upgrade if you don't wish to - but keeping Yarn up-to-date is generally a good idea, as they tend to often come with a significant amount of performance improvements, bugfixes, and new features.

YN0089 - TIPS_NOTICE

我们的研究表明,即使是我们的高级用户也并不总是知道 Yarn 中一些不太明显的功能。为了提高可发现性,在本地机器上,Yarn 每天都会显示一条关于其包含的一些要点的提示。也许其中一个有一天会帮助你改善你的基础设施?

¥Our research showed that even our power users aren't always aware of some of the less obvious features in Yarn. To improve discoverability, on local machines, Yarn will display every day a tip about some of the nuggets it contains. Perhaps one of them will help you improve your infrastructure someday?

YN0090 - OFFLINE_MODE_ENABLED

启用后,enableOfflineMode 标志会告诉 Yarn 忽略远程注册表并仅从其内部缓存中提取数据。当在飞机或火车等网络受限的环境中工作时,这是一种方便的模式。

¥When enabled, the enableOfflineMode flag tells Yarn to ignore remote registries and only pull data from its internal caches. This is a handy mode when working from within network-constrained environments such as planes or trains.

要退出离线工作模式,请检查如何通过运行 yarn config --why 启用它。如果是 <environment>,则在终端中运行 unset YARN_ENABLE_OFFLINE_MODE。否则,从相关的 .yarnrc.yml 文件中删除 enableOfflineMode 标志。

¥To leave the offline work mode, check how it got enabled by running yarn config --why. If <environment>, run unset YARN_ENABLE_OFFLINE_MODE in your terminal. Otherwise, remove the enableOfflineMode flag from the relevant .yarnrc.yml files.