gun
gun copied to clipboard
Buffer is not defined in ison.js when using Vite build tool

Store adapter isn't working in recent GitHub version. Throws the error on app initiation. @amark
Here's the repro: https://github.com/davay42/gun-vite-repro/blob/master/src/App.vue
Here's the hack that makes the new Gun v. 0.2020.1236
work with Vite. Had to use https://github.com/feross/buffer and https://github.com/YuzuJS/setImmediate for it. Seems ok as they're quite small in size.
That's pretty strange @amark: why introduce such dependencies node dependencies? It used to work without it before and adding these introduces polyfill so gunjs can work on a browser... (at least, as far as I can understand)
As I understand the problem appears only for Vite build system. When people use the compiled Gun.js in the browser everything works fine.
As I understand the problem appears only for Vite build system.
I faced the same in rollup
For those TypeScript users out there, just found out that instead of:
document.setImmediate = setImmediate
which will throw an error, we can use:
window.setImmediate = setTimeout
Btw, it also avoids us to add a dependency to https://github.com/YuzuJS/setImmediate ;)
@philippedasilva-orizone Thank you for the update! That works just fine! �
// polyfiils for Gun 0.2020.1236
import { Buffer } from 'buffer'
window.Buffer = Buffer
window.setImmediate = setTimeout