You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Yarn循环依赖解析到本地工作区并强制拉取仓库最新发布版本

Fixing Yarn 3 PnP's Local Workspace Resolution for Circular Dependencies

Hey there, I’ve run into similar circular dependency quirks with Yarn 3 PnP before—here are three solid ways to force Yarn to pull the latest published version from the registry instead of resolving to your unbuilt local workspace:

1. Use resolutions to lock the dependency version

Add a resolutions field to your base package's package.json to explicitly tell Yarn to use the published version of your package:

{
  "resolutions": {
    "your-base-tool-package": "^1.2.3"
  }
}

Replace ^1.2.3 with the actual latest version of your package on the registry. Yarn will prioritize this configuration over the local workspace link.

2. Exclude your package from workspace dependencies

If you're working in a monorepo, tweak your .yarnrc.yml to exclude your base tool package from being treated as a workspace dependency:

workspaceDependencies:
  - "!your-base-tool-package"

This tells Yarn to skip checking the local workspace for this package and go straight to the registry for the latest release.

3. Install with --no-workspace-root (one-off fix)

For a quick temporary fix, install the dev dependency with the --no-workspace-root flag to bypass the local workspace resolution:

yarn add your-base-tool-package --dev --no-workspace-root

This forces Yarn to pull the published version instead of linking to your local unbuilt copy.

A quick note on Yarn's default behavior

Yarn's default priority for local workspace dependencies is meant to make monorepo development easier—letting you test changes to local packages without publishing them first. But in your circular dependency scenario where the local package isn't built yet, this backfires. The above fixes all work around that default to get you the stable published version you need.

内容的提问来源于stack exchange,提问作者Doofus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 21:12:36