nrwl/nx-ai-agents-config

link-workspace-packages

让代理识别消费方和提供方,用对应包管理器声明工作区依赖。

查看源码

详细说明

适合这样的情况:应用已经引用同仓库中的 UI 库或数据包,文件也确实存在,却没有在消费方声明正确依赖。这个 Skill 从“谁导入谁”入手,区分消费包与提供包,再处理工作区依赖关系。编辑器能通过路径别名找到文件,并不代表实际安装和运行时也能解析这个包。

原文分别提供 npm、pnpm、Yarn 与 Bun 的工作区做法,先检查根目录的 packageManager、锁文件和工作区配置,再选择命令。例如 pnpm 示例通过 --filter 指定消费包,并以 --workspace 要求使用本地包;修改后的 package.json 与锁文件仍需检查,避免依赖加到了根包或错误的应用。

验证要结合实际安装模式。Yarn PnP 可以通过 .pnp.cjs 解析依赖,没有 node_modules 不等于安装失败。连接完成后仍要检查包的 exports、构建产物和受影响项目的类型检查或构建;这个 Skill 不保证一次安装就能修好所有导入错误。

需要准备什么

  • 消费包、提供包的准确名称、各自 package.json,以及失败的导入语句。
  • 根目录的包管理器及版本、锁文件、工作区范围和当前依赖配置。

可以得到什么

  • 正确消费方中的本地依赖声明及相应安装状态。
  • 区分依赖连接、导出配置和构建产物问题的验证结果。

使用步骤

  1. 先确认导入关系,以及两个包是否都在工作区范围内。
  2. 根据实际包管理器和版本选择工作区语法,不混用不同工具的示例。
  3. 将依赖添加到目标消费包,核对清单与锁文件的变化。
  4. 按当前链接模式检查解析,再运行相关项目已有的构建或类型检查。

限制与检查

  • 同名注册表包不一定就是仓库中的本地提供包。
  • 启用 Yarn PnP 时,不以是否存在 node_modules 判断成功。
  • 依赖已连接仍报错时,继续检查 exports 和所需构建产物。
  • 迁移代码及历史用 nx-import;安装框架集成用 nx-plugins,三者职责不同。

常见问题

必须先使用 Nx 吗?

已审原文使用包管理器的工作区能力,没有声明必须安装 Nx 或 Nx MCP。仍需要能读取目标仓库的兼容代理及实际项目上下文。

nrwl/nx 中的同名版本有什么区别?

本次核对的两个固定提交中,Skill 目录完全相同。本页对应 nx-ai-agents-config 的分发入口;按现有配置选择来源,不应把另一入口当成额外能力重复安装。

这里的流程经过独立执行测试了吗?

没有。这份说明依据固定版本的 Skill 和包管理器官方文档整理,不代表已在你的仓库中运行或验证。

安装这个 Skill

通过 Skills CLI,从已验证的 GitHub 来源添加这个 Skill。

npx skills add https://github.com/nrwl/nx-ai-agents-config --skill link-workspace-packages

来源信息

仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

Link Workspace Packages

Add dependencies between packages in a monorepo. All package managers support workspaces but with different syntax.

Detect Package Manager

Check whether there's a packageManager field in the root-level package.json.

Alternatively check lockfile in repo root:

  • pnpm-lock.yaml → pnpm
  • yarn.lock → yarn
  • bun.lock / bun.lockb → bun
  • package-lock.json → npm

Workflow

  1. Identify consumer package (the one importing)
  2. Identify provider package(s) (being imported)
  3. Add dependency using package manager's workspace syntax
  4. Verify symlinks created in consumer's node_modules/

pnpm

Uses workspace: protocol - symlinks only created when explicitly declared.

bash
# From consumer directory
pnpm add @org/ui --workspace

# Or with --filter from anywhere
pnpm add @org/ui --filter @org/app --workspace

Result in package.json:

json
{ "dependencies": { "@org/ui": "workspace:*" } }

yarn (v2+/berry)

Also uses workspace: protocol.

bash
yarn workspace @org/app add @org/ui

Result in package.json:

json
{ "dependencies": { "@org/ui": "workspace:^" } }

npm

No workspace: protocol. npm auto-symlinks workspace packages.

bash
npm install @org/ui --workspace @org/app

Result in package.json:

json
{ "dependencies": { "@org/ui": "*" } }

npm resolves to local workspace automatically during install.


bun

Supports workspace: protocol (pnpm-compatible).

bash
cd packages/app && bun add @org/ui

Result in package.json:

json
{ "dependencies": { "@org/ui": "workspace:*" } }

Examples

Example 1: pnpm - link ui lib to app

bash
pnpm add @org/ui --filter @org/app --workspace

Example 2: npm - link multiple packages

bash
npm install @org/data-access @org/ui --workspace @org/dashboard

Example 3: Debug "Cannot find module"

  1. Check if dependency is declared in consumer's package.json
  2. If not, add it using appropriate command above
  3. Run install (pnpm install, npm install, etc.)

Notes

  • Symlinks appear in <consumer>/node_modules/@org/<package>
  • Hoisting differs by manager:
  • npm/bun: hoist shared deps to root node_modules
  • pnpm: no hoisting (strict isolation, prevents phantom deps)
  • yarn berry: uses Plug'n'Play by default (no node_modules)
  • Root package.json should have "private": true to prevent accidental publish

按任务相关推荐

来自同一仓库

更多 Skills

全部 Skills
nrwl
社区

nx-workspace

Explore and understand Nx workspaces. USE WHEN answering questions about the workspace, projects, or tasks. ALSO USE WHEN an nx command fails or you need to check available targets/configuration before running a task. EXAMPLES: 'What projects are in this workspace?', 'How is project X configured?', 'What depends on library Y?', 'What targets can I run?', 'Cannot find configuration for task', 'debug nx task failure'.

累计安装量
10.1万
GitHub Stars
29
最近更新
11月20日
nrwl
社区

nx-import

Import, merge, or combine repositories into an Nx workspace using nx import. USE WHEN the user asks to adopt Nx across repos, move projects into a monorepo, or bring code/history from another repository.

1小时安装量
1
GitHub Stars
29
最近更新
11月20日
nrwl
社区

nx-plugins

Find and add Nx plugins. USE WHEN user wants to discover available plugins, install a new plugin, or add support for a specific framework or technology to the workspace.

1小时安装量
1
GitHub Stars
29
最近更新
11月20日
nrwl
社区

nx-generate

Generate code using nx generators. INVOKE IMMEDIATELY when user mentions scaffolding, setup, structure, creating apps/libs, or setting up project structure. Trigger words - scaffold, setup, create a new app, create a new lib, project structure, generate, add a new project. ALWAYS use this BEFORE calling nxdocs or exploring - this skill handles discovery internally.

1小时安装量
7
GitHub Stars
28
最近更新
10月7日