我是这么解决的:
- 删除 node_modules 文件夹
- 运行 npm install
再编译。
我的代码如下:
// src/index.js
import L from 'leaflet';
import * as SuperMap from '@supermap/iclient-leaflet';
L.supermap = SuperMap;
window.onload = function () {
var url = "http://localhost:8090/iserver/services/map-world/rest/maps/World";
var map = L.map('map', {
crs: L.CRS.EPSG4326,
center: [0, 0],
maxZoom: 18,
zoom: 1
});
console.log(SuperMap);
L.supermap.tiledMapLayer(url).addTo(map);
}
// package.json 依赖片段
"dependencies": {
"@supermap/iclient-leaflet": "^9.1.1",
"leaflet": "^1.3.1"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
}