thirdweb-dev / react

Ultimate collection of React hooks for your web3 apps
https://docs.thirdweb.com/react
Apache License 2.0
80 stars 29 forks source link

Thirdweb doesn't seem to work with Vite.js #61

Closed ricardo-cavalheiro closed 2 years ago

ricardo-cavalheiro commented 2 years ago

So, I just scaffolded a vite js app with react-ts template and installed @thirdweb-dev/react and @thirdweb-dev/sdk. But I keep getting this error when I place ThirdwebProvider anywhere in the code:

Uncaught ReferenceError: global is not defined
    at node_modules/.pnpm/readable-stream@3.6.0/node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:48:21)
    at __require2 (chunk-JR3K7AQW.js?v=203bfd85:47:50)
    at node_modules/.pnpm/readable-stream@3.6.0/node_modules/readable-stream/readable-browser.js (readable-browser.js:1:28)
    at __require2 (chunk-JR3K7AQW.js?v=203bfd85:47:50)
    at node_modules/.pnpm/keccak@3.0.2/node_modules/keccak/lib/api/keccak.js (keccak.js:1:23)
    at __require2 (chunk-JR3K7AQW.js?v=203bfd85:47:50)
    at node_modules/.pnpm/keccak@3.0.2/node_modules/keccak/lib/api/index.js (index.js:1:22)
    at __require2 (chunk-JR3K7AQW.js?v=203bfd85:47:50)
    at node_modules/.pnpm/keccak@3.0.2/node_modules/keccak/js.js (js.js:1:18)
    at __require2 (chunk-JR3K7AQW.js?v=203bfd85:47:50)

My guess is that ThirdwebProvider doesn't check the environment it is currently running in and tries to call global which is only available in the Node.js environment. You can reproduce this error in this git repository: https://github.com/ricardo-passos/buildspace-dao

jnsdls commented 2 years ago

hey @ricardo-passos, thanks for calling this out. I think we can provide a better experience here.

FWIW we have templates that work out of the box here: https://github.com/thirdweb-example (including vite templates).

With that said we should handle this properly I'll have an update for you shortly.

jnsdls commented 2 years ago

this should be fixed by: #62

@ricardo-passos please let me know if you still run into issues after upgrading to the latest version, thanks again for pointing this out to us!

ricardo-cavalheiro commented 2 years ago

@jnsdls Your fix apparently did the work. I create a new local repo with a fresh install of the packages and everything seems ok.