reactjs - 模块解析失败:使用这些加载器处理了意外的令牌文件:
问题描述
我想使用反应将地图添加到我的网站
但是当我启动应用程序时,它说,
./node_modules/@react-leaflet/core/esm/path.js 10:41 模块解析失败:意外令牌 (10:41) s\Soufiane\Downloads\WORK\samsara_v1\samsara_v1\src\SearchPage' 文件已处理这些装载机:
- ./node_modules/babel-loader/lib/index.js 你可能需要一个额外的加载器来处理这些加载器的结果。| useEffect(function updatePathOptions() { | if (props.pathOptions !== optionsRef.current) {
const options = props.pathOptions ?? {};
| element.instance.setStyle(options); | optionsRef.current = 选项;
import React from 'react';
import { render } from 'react-dom';
import { MapContainer, Marker, Popup, TileLayer } from 'react-leaflet';
import ClusterLayer from 'react-leaflet-cluster-layer';
const position = { lng: -122.673447, lat: 45.522558 };
const markers = [
{
position: { lng: -122.673447, lat: 45.5225581 },
text: 'Voodoo Doughnut',
},
{
position: { lng: -122.6781446, lat: 45.5225512 },
text: 'Bailey\'s Taproom',
},
{
position: { lng: -122.67535700000002, lat: 45.5192743 },
text: 'Barista'
}
];
class ExampleClusterComponent extends React.Component {
render() {
const style = {
border: 'solid 2px darkgrey',
borderRadius: '8px',
backgroundColor: 'white',
padding: '1em',
textAlign: 'center'
};
const cluster = this.props.cluster;
if (cluster.markers.length == 1) {
return (
<div style={style} >{cluster.markers[0].text}</div>
);
}
return (
<div style={style}>{cluster.markers.length} items</div>
);
}
}
const map = (
<MapContainer center={position} zoom={13}>
<ClusterLayer
markers={markers}
clusterComponent={ExampleClusterComponent} />
<TileLayer
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
/>
</MapContainer>
);
export default map
解决方案
更新你的 package.json。尝试使用以下软件包的这些版本:
"react-leaflet": "2.7.0",
"react-leaflet-markercluster": "2.0.0",
"leaflet": "^1.6.0",
"leaflet.markercluster": "^1.5.0",
推荐阅读
- docker - Maven 错误未知主机 repo.maven.apache.org
- php - 如何制作一个不区分大小写的部分文本搜索引擎,该引擎将 Regex 与 MongoDB 和 PHP 结合使用?
- algorithm - java中二维数组的最大路径,任意单元开始
- python - 如何从 iFrame 索引切换回相对父级?
- salesforce - 风格化 LWC 电台列表?
- spring-integration - 如何威胁春季云数据流上的错误?
- javascript - 在 D3 中添加大量文本元素会导致性能问题
- ios - iOS 的 React-Native 升级:选项
- php - 如何在新页面 mpdf 库中禁用标题重复?
- python - 我的 python 日期时间没有在我的 django 应用程序中得到验证