如何解决react-leaflet-heatmap-layer 抛出错误:TypeError:超级表达式必须为空或函数,而不是未定义的
我正在尝试使用 react-leaflet-heatmap-layer 模块向我的 react-leaflet 地图添加热图。我通过 npm 安装了它,并按照所有正确的步骤进行了操作,但我无法让组件工作。
我遇到了两个错误:
1.找不到模块“react-leaflet-heatmap-layer”的声明文件。
Could not find a declaration file for module 'react-leaflet-heatmap-layer'. 'path/node_modules/react-leaflet-heatmap-layer/lib/HeatmapLayer.js' implicitly has an 'any' type. Try `npm i --save-dev @types/react-leaflet-heatmap-layer` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-leaflet-heatmap-layer';`
@types 不适用于这个模块,所以我试图通过在 src 文件夹中创建一个 global.d.ts 文件来修复它,尽管我怀疑我做对了,因为这个错误似乎只有当我有.d.ts 文件在我的 VSCode 中打开。其他来源建议编辑 tsconfig.json 文件,但我找不到,我怀疑我的 React 项目是否应该有一个。
2.类型错误:超级表达式必须为空或函数,不能为未定义
当我执行 npm start
时,此错误会显示在浏览器上。根据另一个在线消息来源,这个错误是由不同的传单模块引起的,因为它与更新版本的 react 不兼容,但是我不确定这是否也是我的代码的错误。以下是我正在使用的 react 版本和模块:
"leaflet": "^1.7.1","leaflet.heat": "^0.2.0","react": "^17.0.2","react-dom": "^17.0.2","react-leaflet": "^3.2.0","react-leaflet-heatmap-layer": "^2.0.0",
网上有很多其他消息来源说这个错误很可能是由于错误地导入了模块,但我很确定我做了文档告诉我要做的一切。\
import HeatmapLayer from "react-leaflet-heatmap-layer";
请帮忙。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。