mf-shared-deps

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Step 1: Call the
mf-context
Skill (pass
$ARGUMENTS
) to collect MFContext.
Step 2: Serialize MFContext to JSON and pass it to the check script via the
--context
argument:
bash
node scripts/shared-config-check.js --context '<MFContext-JSON>'
Process each item in the output
results
array:
SHARED-EXTERNALS-CONFLICT · warning — same library in both
shared
and
externals
  • shared
    and
    externals
    are not mutually exclusive in config, but the same library must not appear in both — it causes the module to be excluded from the bundle while also being declared as shared, leading to runtime failures
  • Show the conflicting library name and guide the user to remove it from one of the two configs
SHARED-TRANSFORM-IMPORT · warning — antd/arco UI library shared but
transformImport
is active
  • babel-plugin-import
    (or the built-in
    transformImport
    in Modern.js / Rsbuild) rewrites import paths at build time, which prevents the shared dep from being recognized and causes sharing to fail silently
  • Fix:
    • Modern.js / Rsbuild: set
      source.transformImport = false
      to disable the built-in behavior
    • Other bundlers: remove
      babel-plugin-import
      from the Babel config
  • Show which UI library triggered the warning
SHARED-MULTI-VERSION · warning — multiple versions of the same shared package detected
  • The build artifacts contain more than one version of a shared package, meaning the version negotiation failed and both host and remote are each bundling their own copy
  • Recommended fix: add an
    alias
    in the bundler config so all projects resolve to the same physical file
  • Show the detected versions
When results is empty
  • Inform the user that no shared dependency conflicts were detected in this project
  • Remind them that a complete picture requires running the same check in both the host and every remote
步骤1:调用
mf-context
Skill(传入
$ARGUMENTS
)来收集MFContext。
步骤2:将MFContext序列化为JSON,通过
--context
参数传递给检查脚本:
bash
node scripts/shared-config-check.js --context '<MFContext-JSON>'
处理输出
results
数组中的每个项:
SHARED-EXTERNALS-CONFLICT · 警告 — 同一库同时出现在
shared
externals
  • shared
    externals
    在配置中并非互斥,但同一库不能同时出现在两者中——这会导致模块被排除在打包文件之外,同时又被声明为共享,进而引发运行时错误
  • 显示冲突的库名称,并引导用户从其中一个配置中移除该库
SHARED-TRANSFORM-IMPORT · 警告 — antd/arco UI库已设置共享,但
transformImport
处于激活状态
  • babel-plugin-import
    (或Modern.js / Rsbuild中的内置
    transformImport
    )会在构建时重写导入路径,这会导致共享依赖无法被识别,进而使共享功能静默失效
  • 修复方案:
    • Modern.js / Rsbuild:设置
      source.transformImport = false
      以禁用内置行为
    • 其他打包工具:从Babel配置中移除
      babel-plugin-import
  • 显示触发警告的UI库名称
SHARED-MULTI-VERSION · 警告 — 检测到同一共享包存在多个版本
  • 构建产物中包含同一共享包的多个版本,这意味着版本协商失败,宿主和远程应用各自打包了自己的副本
  • 推荐修复方案:在打包工具配置中添加
    alias
    ,使所有项目解析到同一个物理文件
  • 显示检测到的版本
当results为空时
  • 告知用户当前项目中未检测到共享依赖冲突
  • 提醒用户,若要获取完整的检查结果,需要在宿主应用和所有远程应用中都运行相同的检查