bugra9 / gdal3.js

Convert raster and vector geospatial data to various formats and coordinate systems entirely in the browser.
https://gdal3.js.org
GNU Lesser General Public License v2.1
300 stars 45 forks source link

TypeError: Cannot read properties of undefined (reading 'prototype') #30

Closed gy1016 closed 2 years ago

gy1016 commented 2 years ago

when I use gdal3.js in a vite + vue3 project, import initGdalJs from 'gdal3.js' throw error -> TypeError: Cannot read properties of undefined (reading 'prototype') how do i handle it

// app.vue
<script setup>
import initGdalJs from 'gdal3.js';
// TypeError: Cannot read properties of undefined (reading 'prototype')
console.log(initGdalJs);
</script>

<template>
  <div>Hello Vue 3 + Vite</div>
</template>
bugra9 commented 2 years ago

Hi,

I could not reproduce the same error, but while trying with vite+vue3, I encountered another error. I was able to overcome this issue by compiling gdal3.js with rollup instead of webpack. I have released new version 2.1.0 and this version is working for me as below. Can you try this version?

<script setup>
import { ref } from 'vue'
import workerUrl from 'gdal3.js/dist/package/gdal3.js?url'
import dataUrl from 'gdal3.js/dist/package/gdal3WebAssembly.data?url'
import wasmUrl from 'gdal3.js/dist/package/gdal3WebAssembly.wasm?url'
import initGdalJs from 'gdal3.js';

const paths = {
  wasm: wasmUrl,
  data: dataUrl,
  js: workerUrl,
};

const count = ref(0);
initGdalJs({paths}).then((Gdal) => {
    count.value = Object.keys(Gdal.drivers.raster).length + Object.keys(Gdal.drivers.vector).length;
});
</script>

<template>
  <div>Number of drivers: {{ count }}</div>
</template>
gy1016 commented 2 years ago

thx