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

Angular17项目迁移Module Federation至Native Federation执行命令报错

解决Module Federation迁移时"architect.build.options.main not found"错误

针对你在从ngx-build-plus+Module Federation 17迁移到Native Federation过程中遇到的错误,提供以下排查和解决步骤:

  • 检查项目配置层级
    确认angular.json中项目的build.options.main处于正确的路径层级,即结构为projects[你的项目名].architect.build.options.main,而非嵌套在configurations下的某个环境配置(比如production)中。部分项目会在环境配置里覆盖main字段,但迁移命令只会读取根级的build.options配置。

  • 对齐Module Federation与Angular CLI版本
    Module Federation 18.x对应Angular 18,而你当前使用Angular CLI 17,版本不匹配可能导致命令读取配置异常。先降级Module Federation到17.x兼容版本:

    npm install @angular-architects/module-federation@17.4.0 --save-dev
    

    之后再重新执行ng g @angular-architects/module-federation:remove --project project-name命令。

  • 先手动恢复官方构建器
    迁移命令可能对ngx-build-plus的构建器配置兼容性不好,先手动修改angular.json:
    将architect.build.builder从"ngx-build-plus:browser"改为官方的"@angular-devkit/build-angular:browser",同时移除ngx-build-plus相关的额外配置(比如extraWebpackConfig),再执行移除命令。

  • 验证项目名称准确性
    确保命令中的project-name与angular.json里的项目名称完全一致,包括大小写、连字符等细节,避免因名称不匹配导致配置读取失败。

  • 跳过移除命令,手动迁移到Native Federation
    如果上述方法都无效,直接手动完成迁移:

    1. 卸载旧依赖:
      npm uninstall ngx-build-plus @angular-architects/module-federation
      
    2. 安装Native Federation:
      npm install @angular-architects/native-federation@18 --save-dev
      
    3. 初始化Native Federation配置:
      ng g @angular-architects/native-federation:init --project project-name
      
    4. 手动调整angular.json中的构建配置,确保使用官方构建器并包含Native Federation的相关设置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 09:34:59