calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
714 stars 228 forks source link

Error using in Vue3 #200

Open JakobMiksch opened 8 months ago

JakobMiksch commented 8 months ago

When I use shpjs in a vanilla Vue3 app, I get this error:

image

How to reproduce:

Create a new Vue3 app

npm create vue@latest

install dependencies:

npm install 
npm install shpjs --save

In App.vue import

import shp from "shpjs"

then the error from above will appear.

JakobMiksch commented 8 months ago

workaround:

add this to vite.config.ts (taken from here):

 export default defineConfig({
    define: {
      global: {},
    },
  })

also install buffer as dev dependency:

npm i -D buffer
# or
yarn add -D buffer
Preyou commented 7 months ago

我是这么解决的

import { Buffer } from 'buffer'
window.Buffer = Buffer

window.global = globalThis
sqlAIJava commented 4 months ago

我就是这么解决的

import { Buffer } from 'buffer'
window.Buffer = Buffer

window.global = globalThis

在main.ts中使用即可