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

Yarn v3工作区配置nodeLinker:node-modules不生成node_modules无法启动包

解决方案

1. 修复子包重名问题

package-b的package.json中name字段错误设置为package-a,与package-a重名会导致Yarn工作区无法正确识别和链接包。修改package-b的package.json:

{
  "name": "package-b", // 改为正确的包名
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "start": "react-scripts start",
    ...
  },
  "dependencies": {
    "cross-env": "5.0.5",
    "package-a": "1.0.0"
  }
}

2. 确保Yarn配置文件正确生效

  • 修正配置文件名:Yarn v3默认读取根目录的.yarnrc.yml(隐藏文件,前缀带.),你的目录结构中配置文件为yarnrc.yaml(无.),会导致Yarn无法识别配置。将配置文件重命名为.yarnrc.yml,内容保持:
    nodeLinker: node-modules
    
  • 清理旧PnP相关文件:删除根目录下的.pnp.cjs、.pnp.loader.mjs、.yarn文件夹,避免旧配置干扰。
  • 清除缓存并重新安装:
    yarn cache clean
    yarn install
    
    执行后根目录会生成node_modules文件夹,子包会被正确链接到根目录的node_modules中。

3. 验证工作区命令

完成上述步骤后,在根目录执行:

yarn workspace package-b start

此时即可正常启动package-b,package-a的依赖会通过工作区链接加载。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 04:06:03