【发布时间】:2020-09-28 20:38:41
【问题描述】:
我按照React Locate on map 的回答,在 gatsby 开发模式下一切正常。但是如果我构建我的 gatsby 项目,它会抛出一个 webpack 错误
“WebpackError: TypeError: Object(...) is not a function”。
如果我将代码从
export default withLeaflet(LocateControl);
至
export default withLeaflet(LocateControl);
构建工作,但我在浏览器中得到错误
“类型错误:this.props.leaflet 未定义”
import React, { Component } from "react";
import { withLeaflet } from "react-leaflet";
import Locate from "leaflet.locatecontrol";
class LocateControl extends Component {
componentDidMount() {
const { options, startDirectly } = this.props;
const { map } = this.props.leaflet;
const lc = new Locate(options);
lc.addTo(map);
if (startDirectly) {
// request location update and set location
lc.start();
}
}
render() {
return null;
}
}
export default withLeaflet(LocateControl);
locate-plugin 应该可以工作,但现在构建不工作。
【问题讨论】:
标签: gatsby react-leaflet