首页 / 浏览问题 / WebGIS / 问题详情
react+vite+ts+@supermap/iclient-ol报错
2EXP 2023年05月24日
"@supermap/iclient-ol": "^11.1.0-beta"

简单创建的react+vite+ts项目,集成@supermap/iclient-ol之后运行报错:

index.js:11 Uncaught TypeError: Cannot read properties of undefined (reading 'from')
    at node_modules/safe-buffer/index.js (index.js:11:12)
    at __require2 (chunk-TFWDKVI3.js?v=cf50ce66:18:50)
    at node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:55:14)
    at __require2 (chunk-TFWDKVI3.js?v=cf50ce66:18:50)
    at node_modules/readable-stream/readable-browser.js (readable-browser.js:1:28)
    at __require2 (chunk-TFWDKVI3.js?v=cf50ce66:18:50)
    at node_modules/from2/index.js (index.js:1:16)
    at __require2 (chunk-TFWDKVI3.js?v=cf50ce66:18:50)
    at node_modules/into-stream/index.js (index.js:2:14)
    at __require2 (chunk-TFWDKVI3.js?v=cf50ce66:18:50)

测试代码:

const url = "https://iserver.supermap.io/iserver/services/map-world/rest/maps/World";
const map = new Map({
    target: 'map',
    controls: control.defaults({attributionOptions: {collapsed: false}}).extend([new Logo()]),
    view: new View({
        center: [0, 0],
        zoom: 2,
        projection: 'EPSG:4326'
    })
});
const layer = new TileLayer({
    source: new TileSuperMapRest({
        url: url,
        wrapX: true
    }),
    projection: 'EPSG:4326'
});
map.addLayer(layer);

1个回答

您好,检查一下是否有引入提示的依赖包safe-buffer/index.js,没有的话重新引入一下。
1,865EXP 2023年05月24日
safe-buffer/index.js 已经引入了,我试了下11.0.1版本不会报错。

参考一下vite引入的问题https://github.com/vitejs/vite/issues/7105

使用webpack是否正常呢?

...