Uncaught Error: Element type is invalid: expected a string react-leaflet

Uncaught Error: Element type is invalid: expected a string react-leaflet

我在使用 create-react-app 脚本创建的项目中集成了 react-leaflet。我关注这个 example.

一切正常,但是当我尝试使用 GeoJsoncomponent imported as:

import { Map, TileLayer, Popup, GeoJson } from 'react-leaflet'

我有以下警告。

warning.js:35 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check your code at index.js:47.

和错误

Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of Leaflet

而且我在地图上看不到该地区。

如何解决这个问题? 谢谢 .

根据 react-leaflet 最近的变化, 您应该尝试导入 GeoJSON 而不是 GeoJson。 它已更改以匹配最近的传单库更改。