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

Angular Electron项目运行时ng-zorro模块找不到问题求助

问题描述

我在Angular 14.2.7项目中使用ng-zorro v14.1.1,该项目为Angular Electron项目,Electron版本为21.2.0。运行项目时构建提示找不到ng-zorro相关模块,但对应文件实际存在于项目中。已尝试删除node_modules,重新执行ng add ng-zorro-antd和npm install ng-zorro-antd,问题仍未解决。

解决建议
  • 检查TypeScript路径配置
    确认tsconfig.json或tsconfig.app.json中是否正确配置ng-zorro的路径映射,确保编译器能识别模块位置:

    {
      "compilerOptions": {
        "paths": {
          "ng-zorro-antd/*": ["./node_modules/ng-zorro-antd/*"]
        }
      }
    }
    
  • 清理Angular构建缓存
    执行命令清理Angular缓存,避免缓存导致的模块解析异常:

    ng cache clean
    
  • 重置依赖锁文件
    删除package-lock.json(若用yarn则删除yarn.lock)后重新安装依赖,确保版本依赖完全一致:

    rm package-lock.json
    npm install
    
  • 适配Electron构建配置
    Angular Electron项目存在主/渲染进程的模块解析差异,检查angular.json的构建配置,将ng-zorro加入允许的CommonJS依赖列表:

    {
      "projects": {
        "你的项目名称": {
          "architect": {
            "build": {
              "options": {
                "allowedCommonJsDependencies": ["ng-zorro-antd"]
              }
            }
          }
        }
      }
    }
    
  • 验证组件导入路径
    检查项目中所有ng-zorro组件的导入语句,确保路径拼写正确,例如正确写法:import { NzButtonModule } from 'ng-zorro-antd/button',避免相对路径或拼写错误。

  • 手动重建依赖链接
    在项目根目录执行以下命令,强制建立本地模块链接:

    npm link ng-zorro-antd
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 23:35:49