DHTMLX Spreadsheet - global is undefined (vite + vue 2)

120 Views Asked by At

I Installed [email protected] in a Vue + Vite Project.

But It Gives an Error That: Cannot read properties of undefined (reading 'setImmediate')

DHTMLX Spreadsheet - global is undefined (vite + vue 2)

DHTMLX Spreadsheet - global is undefined (vite + vue 2)

I Try a Vue + Webpack Project with This Libray and Everything Is Fine.

Also tried: define: { global: 'globalThis' } in Vite Config File and it Doesn't Affect.

The Webpack Project: https://github.com/DHTMLX/vuejs-widgets

I Think This Package Has Issues With Bite, Is There Anyway to Fix This in Vite?

1

There are 1 best solutions below

0
Aquatic On

You can check solution there https://github.com/bevacqua/dragula/issues/602

It seems that next in the vite.config.js must solve the issue

import { defineConfig } from 'vite'

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

if somehow it doesn't work, you can try to add the next code before including the spreadhsheet's js file

<script>
if (typeof (window as any).global === 'undefined') {
  (window as any).global = window;
}
</script>
<script src="spreadsheet.js"></script>