Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Right-hand side of 'instanceof' is not an object #201

Open
simplexag opened this issue Nov 4, 2023 · 3 comments
Open

TypeError: Right-hand side of 'instanceof' is not an object #201

simplexag opened this issue Nov 4, 2023 · 3 comments

Comments

@simplexag
Copy link

I keep getting the following error

shp.js?t=1699109482459:14409 Uncaught (in promise) TypeError: Right-hand side of 'instanceof' is not an object
at isArrayBuffer (shp.js?t=1699109482459:14409:22)
at toBuffer (shp.js?t=1699109482459:14397:11)
at shp.parseShp (shp.js?t=1699109482459:14538:13)

Using Vue 3

 methods: {
    async openZip() {  
    var reader = new FileReader();
      reader.readAsArrayBuffer(this.file[0]);
      reader.onload = () => {
        this.parseShape(reader.result);
      }
    },
    async parseShape(data) {
        shp.parseShp(data).then(geojson => {
          console.log(geojson); 
        })

    },
  }

Thank you for any help!

@pChao3
Copy link

pChao3 commented Nov 17, 2023

+1

@kasenZrbl
Copy link

这个是index.js文件里有一处检验代码出错了,是之前设置global对象时留下的问题
function isArrayBuffer (subject) {
return subject instanceof global.ArrayBuffer || Object.prototype.toString.call(subject) === '[object ArrayBuffer]';
}
这个函数会检验传输的是否为二进制流,里面的逻辑判断使用了global这个全局变量,我看之前给的解决方案是在config文件内define了一个空的global全局变量,但是ArrayBuffer这个变量只有在window里面有,所有只需要在使用shpjs库函数前,执行一下
global = window ;
让global拥有window的属性方法即可

@sqlAIJava
Copy link

如果是vite项目,在vite.config.ts中加入global: 'window'
export default defineConfig({
define: {
global: 'window'
},
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants