switchboard-xyz / sb-on-demand-examples

9 stars 7 forks source link

running client code in browser: os__WEBPACK_IMPORTED_MODULE_6__.homedir is not a function #17

Open JimLynchCodes opened 1 week ago

JimLynchCodes commented 1 week ago

The very first line of crypto stuff in the client code here makes this call to the "loadEnv" function of switchboard's AnchorUtils object:

const { keypair, connection, program } = await sb.AnchorUtils.loadEnv();

But when I run this in the browser I see this error...

Uncaught runtime errors:
×
ERROR
os__WEBPACK_IMPORTED_MODULE_6__.homedir is not a function
TypeError: os__WEBPACK_IMPORTED_MODULE_6__.homedir is not a function
    at AnchorUtils.<anonymous> (http://localhost:3000/static/js/bundle.js:32247:107)
    at Generator.next (<anonymous>)
    at http://localhost:3000/static/js/bundle.js:32175:67
    at new Promise (<anonymous>)
    at __webpack_modules__../node_modules/@switchboard-xyz/on-demand/dist/esm/anchor-utils/AnchorUtils.js.__awaiter (http://localhost:3000/static/js/bundle.js:32157:10)
    at AnchorUtils.loadEnv (http://localhost:3000/static/js/bundle.js:32246:12)
    at startRoll (http://localhost:3000/static/js/bundle.js:330:81)
    at onClick (http://localhost:3000/static/js/bundle.js:227:102)
    at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:89951:18)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:89995:20)

The example coinflip typescript code works for me when I run it on the command line but not in the browser.

I already solved some other errors trying to port this node client to the browser by creating a config-overrides.js with things like os: require.resolve("os-browserify"), but I'm still getting this error now and stuck on how to get past it. 😕

Thanks!

mgild commented 1 week ago

This function is to pull configs from the solana cli. You can init the anchor program using the anchor sdk instead