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

Angular项目配置SwiperJS提示缺少swiper/types依赖该如何解决?

报错含义

该报错表示swiper_angular这个Angular专属适配包,依赖Swiper核心包中的swiper/types类型定义模块,但你当前项目中安装的Swiper核心包缺失这个导出模块,绝大多数场景是因为Swiper核心包和Angular适配包的版本不匹配,少数情况是包安装过程中文件丢失导致。

修复方案
  • 首先卸载当前已安装的Swiper相关依赖,避免版本残留冲突:
# npm用户执行
npm uninstall swiper @swiper/angular

# yarn用户执行
yarn remove swiper @swiper/angular
  • 重新安装版本匹配的稳定依赖包:
# npm用户执行
npm install swiper@latest @swiper/angular@latest

# yarn用户执行
yarn add swiper@latest @swiper/angular@latest
  • 如果重装后仍有报错,在项目根目录的tsconfig.json的compilerOptions节点下添加路径映射配置即可:
{
  "compilerOptions": {
    // 原有配置保持不变,新增下面的paths配置
    "paths": {
      "swiper/types": ["./node_modules/swiper/types/index.d.ts"]
    }
  }
}
  • 最后清理Angular本地缓存后重启项目:
ng cache clean
ng serve

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 09:24:03