zouyaoji / vue-cesium

🎉 Vue 3.x components for CesiumJS.
https://zouyaoji.top/vue-cesium
MIT License
1.49k stars 321 forks source link

[Bug Report] ReferenceError: global is not defined #110

Closed wjyugutou closed 3 years ago

wjyugutou commented 3 years ago

VueCesium version

3.0.1-beta.5.2

OS/Browsers version

edge

Vue version

3.0.11

Reproduction Link

https://github.com/wjyugutou/cesium.git

Steps to reproduce

Copy the Viewer code to the project and report an error directly index.esm.js:15 Uncaught (in promise) ReferenceError: global is not defined at w2 (index.esm.js:15) at index.esm.js:15 at Generator.next () at index.esm.js:15 at new Promise () at P (index.esm.js:15) at index.esm.js:15 at index.esm.js:15 at Generator.next () at index.esm.js:15

What is Expected?

正常显示组件

What is actually happening?

ReferenceError: global is not defined

zouyaoji commented 3 years ago

This may be a bug of vite, Please refer to: https://github.com/zouyaoji/vue-cesium-vite-starter/blob/c2e7aef97970bcd24d77bd45d4aa63be177ccb12/src/main.ts#L6

and

https://github.com/bevacqua/dragula/issues/602#issuecomment-477734315

zouyaoji commented 3 years ago

You can manually add a global polyfill in your entry file:

// ts
// if (typeof (window as any).global === 'undefined') {
//   (window as any).global = window;
// }

window.global = window