【问题标题】:react-leaflet-control - TypeError: (0 , _reactLeaflet.withLeaflet) is not a functionreact-leaflet-control - TypeError: (0 , _reactLeaflet.withLeaflet) 不是函数
【发布时间】:2019-02-23 17:56:21
【问题描述】:

不知道为什么自定义控件突然在我的 react-leaflet 地图应用程序中不起作用。在“从'react-leaflet-control'导入'Control'”语句期间发生错误。

几周前它曾经工作过,从那时起它就不允许我导入“控制”组件。我们所做的唯一更改是将 react-leaflet 包升级到 2.2.0,仅此而已。

目前我正在使用 react-leaflet-control^1.4.1。很明显,这不兼容/不支持与 react-leaflet-control^2.2.0 一起使用。我尝试通过查看我的旧 package.json 文件降级到 1.9.1,但仍然是同样的问题。我尝试删除所有节点模块并尝试 npm install 更新所有软件包,但仍然是同样的问题。

任何人都知道这里到底出了什么问题,我需要安装任何依赖项来克服这个问题吗?

感谢和问候, ~保罗

【问题讨论】:

    标签: react-leaflet


    【解决方案1】:

    最近有什么变化吗?即不是降级react-leaflet,而是升级react-leaflet-control。升级react-leaflet 后,插件第一次加载失败。因此,开发人员已修复它。这可能是导致问题的原因。

    Here's example on CodeSandbox.

    相关的 javascript 代码在哪里

    import React from "react";
    import ReactDOM from "react-dom";
    import { Map, TileLayer } from "react-leaflet";
    import Control from "react-leaflet-control";
    
    import "./styles.css";
    
    function App() {
      return (
        <Map zoom={13} center={[53.8008, -1.5491]}>
          <TileLayer
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
            attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
          />
          <Control position="topright">
            <div className="so">Top Right Control</div>
          </Control>
        </Map>
      );
    }
    
    const rootElement = document.getElementById("root");
    ReactDOM.render(<App />, rootElement);
    

    相关github issue

    【讨论】:

    • 嗨 Layik,我已尝试升级并尝试了您的选择。我的地图组件位于不同的目录中,我的 app.js 文件中没有任何组件。我现在尝试的是创建一个全新的自定义组件(虚拟反应 dom)并导入该组件并实现减速器操作并能够实现它。不确定来自 node_modules 的 control.js 文件到底有什么问题。似乎不支持最新版本的 .WithLeaflet 方法。
    • 欢迎分享一个 sn-p,以便我可以尝试并提供帮助。你能在沙盒中调整示例吗?
    猜你喜欢
    • 2021-05-01
    • 2021-10-19
    • 2020-03-03
    • 1970-01-01
    • 2020-12-25
    • 2016-02-02
    • 2022-01-08
    • 2021-06-30
    • 2020-08-04
    相关资源
    最近更新 更多