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
文章讲述了在使用Vite开发时遇到importshpfromshpjs报错的问题,解决方法是在main.ts中全局定义global变量并设置Buffer。链接指向了GitHub上的讨论记录提供进一步帮助。
716





