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

已安装leaflet.animatedmarker仍提示模块未找到,如何解决?

解决Module not found: Can't resolve 'leaflet.animatedmarker'问题

核心问题:导入名称与安装的包名不匹配

你安装的包是leaflet.animatedmarker(点分隔),但代码中导入的是leaflet-animatedmarker(横线分隔),这是导致路径解析失败的直接原因,按以下步骤解决:

  • 修正导入语句
    将导入代码改为与包名一致的写法:

    import L from "leaflet";
    import "leaflet.animatedmarker";
    

    保存后重启开发服务器,查看是否解决问题。

  • 如果仍报错:直接导入插件源文件
    部分老版本的Leaflet插件可能未适配ES模块规范,package.json中的main字段指向的文件无法被打包工具正确识别,此时需要直接导入插件的源文件:

    import L from "leaflet";
    import "leaflet.animatedmarker/src/AnimatedMarker.js";
    
  • 重置安装文件
    若存在缓存或安装损坏,执行以下操作重置:

    1. 卸载插件:npm uninstall leaflet.animatedmarker
    2. 删除项目根目录下的node_modules文件夹和package-lock.json文件
    3. 重新安装插件:npm install leaflet.animatedmarker --save
    4. 重启开发服务器

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 08:33:18