import shp from ‘shpjs’
直接使用时,vite会报错global is not defined,以及后续的很多问题
解决方案
- 在main.ts中加入
import { Buffer } from 'buffer'
if (typeof (window as any).global === 'undefined') {
(window as any).global = window;
}
globalThis.Buffer = Buffer
- 使用
import shp from ‘shpjs’
const buffer = e.target.result
shp(buffer).then((res) => {}
3.问题指引
https://github.com/vitejs/vite/discussions/6282