SkynetLabs / skynet-js

A Javascript module made to simplify communication with Sia Skynet portals from the browser.
https://sdk.skynetlabs.com
MIT License
68 stars 9 forks source link

How to use with Vite? #527

Closed Bellisario closed 2 years ago

Bellisario commented 2 years ago

I wanted to try using with Vite, but seems there is a console error:

Uncaught ReferenceError: global is not defined
    at node_modules/randombytes/browser.js (browser.js:16:14)
    at __require2 (chunk-ASBRWZGP.js?v=88b69488:15:50)
    at crypto.js:3:25

Looking the error, seems the randombytes module is not able to get browser global.crypto because it is using global instead of globalThis.

Any solution?

Bellisario commented 2 years ago

Solved this issue by adding a new script tag to HTML page (on the head) with this content:

const global = window
mrcnski commented 2 years ago

Cool, glad it's solved for you. Thanks for bringing it up - might help someone else!