首页 / 浏览问题 / WebGIS / 问题详情
vue3+iclient+ol 报错
8EXP 2023年08月10日

TypeError: Cannot read properties of undefined (reading 'slice')
    at node_modules/readable-stream/lib/_stream_writable.js (@supermap_iclient-ol.js?v=3265d06d:4006:85)
    at __require2 (chunk-S5KM4IGW.js?v=b074cef5:18:50)
    at node_modules/readable-stream/readable-browser.js (@supermap_iclient-ol.js?v=3265d06d:5685:25)
    at __require2 (chunk-S5KM4IGW.js?v=b074cef5:18:50)
    at node_modules/from2/index.js (@supermap_iclient-ol.js?v=3265d06d:5695:20)
    at __require2 (chunk-S5KM4IGW.js?v=b074cef5:18:50)
    at node_modules/into-stream/index.js (@supermap_iclient-ol.js?v=3265d06d:5802:16)
    at __require2 (chunk-S5KM4IGW.js?v=b074cef5:18:50)
    at node_modules/@elastic/elasticsearch/lib/Transport.js (@supermap_iclient-ol.js?v=3265d06d:6217:22)
    at __require2 (chunk-S5KM4IGW.js?v=b074cef5:18:50)

我在vite.config.js中加了 

process: "process/browser",
stream: "stream-browserify",
// zlib: "browserify-zlib",
util: "util"

但还是不管用

"dependencies": {
  "@element-plus/icons-vue": "^2.1.0",
  "@supermap/iclient-ol": "^11.1.0",
  "@turf/turf": "^6.5.0",
  "@vueup/vue-quill": "1.1.0",
  "@vueuse/core": "9.5.0",
  "ant-design-vue": "^3.2.20",
  "axios": "0.27.2",
  "dayjs": "^1.11.8",
  "dplayer": "^1.27.1",
  "echarts": "^5.4.3",
  "echarts-liquidfill": "^3.1.0",
  "element-plus": "^2.3.5",
  "element-pro-components": "^1.2.12",
  "events": "^3.3.0",
  "file-saver": "2.0.5",
  "fuse.js": "6.6.2",
  "js-cookie": "3.0.1",
  "jsencrypt": "3.3.1",
  "nprogress": "0.2.0",
  "ol": "^6.14.1",
  "os-browserify": "^0.3.0",
  "pinia": "2.0.22",
  "stream-browserify": "^3.0.0",
  "util": "^0.12.4",
  "vue": "3.2.45",
  "vue-cropper": "1.0.3",
  "vue-router": "4.1.4",
  "vxe-table": "^4.4.1",
  "xe-utils": "^3.5.11"
},
"devDependencies": {
  "@supermap/babel-plugin-import": "0.0.1",
  "@vitejs/plugin-vue": "3.1.0",
  "@vue/compiler-sfc": "3.2.45",
  "sass": "1.56.1",
  "buffer": "^6.0.3",
  "unplugin-auto-import": "0.11.4",
  "vite": "3.2.3",
  "vite-plugin-compression": "0.5.1",
  "vite-plugin-svg-icons": "2.0.1",
  "vite-plugin-vue-setup-extend": "0.4.0"
}

3 个回答

你好,1、初始化vue+vite成功了吗?根据报错是引入iclient for ol包出错,可以删除重新引入看看。

2、vite+vue引入iclent可以根据博客步骤来:https://blog.csdn.net/supermapsupport/article/details/130778845

1,865EXP 2023年08月10日
1.初始化vue+vite成功了    我

2.那个文档我看过 似乎没太大帮助  我觉得是这个/readable-stream/lib/_stream_writable.js 这个包解析的时候报错了
已自行解决
pool
1
8EXP 2023年08月11日
你好,我这边也出现了同样的问题,上面推荐的那个文档一样也解决不了我的问题,请问您是怎么解决的啊
我来说说我的发现,我浏览器报错是_stream_writeable.js里的这一行

var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;

疑似是找不到process.version这个变量

于是我找到了这个js所属的包readable-stream里的同名js,结果发现其中并没有上面var asyncWrite = xxxx那一行

于是我全文检索了整个工程,找process.version这个关键字,结果在@supermap_iclient-ol.js中找到线索了,其中搜索关键字_stream_writable.js,可以在大约12525行找到了这个js的重写,里面竟然加上了var asyncWrite这一行。

我不知为何要重新加上这一行(因为我翻墙发现老外提了一嘴process.version.slice报错于是相关开发组把这一行删了fix了)
6EXP 2023年09月18日
...