Having trouble using web3auth

I’m trying to add web3auth to my Vite app and running into an issue. I’m following this guide to set this up.

I’m running into this error web3Auth.off is not a function
I’ve polyfilled Buffer and process as the Vite specific guide suggests, so this isn’t the issue.

Wondering if anyone’s seen this before?

Thanks — I can help. You’re reporting an error (so this is an issue report) and I pulled these details from your message:

  • SDK: MetaMask Embedded Wallets (React guide link provided)
  • Platform: Vite (web)
  • Error: web3Auth.off is not a function
  • You’ve already polyfilled Buffer/process per the Vite guide

Quick things that commonly cause this and easy checks you can try now

  • Version / package mismatch: different @web3auth packages (modal/core/web3auth) or mismatched versions can expose different APIs. Confirm you’re using the same web3auth package that the example expects.
  • Wrong object: ensure the object you call .off on is the actual Web3Auth instance (not the provider or an adapter). Log it: console.dir(web3Auth); console.log(typeof web3Auth.off).
  • Import/interop issue: ESM vs CJS default vs named import can change the shape of the imported object. Try the alternative import style if you used default (or named) import.
  • API change: some SDK versions rename or remove event methods (on/off). Check the web3auth SDK docs for your package version to confirm the event API.

What I need from you to move this to the support team (please only share what you can):

  • package.json (or list of related deps + exact versions: @web3auth/* packages, @metamask/embedded-wallets or @metamask/embedded-provider, vite, node)
  • The snippet where you initialize Web3Auth and where you call .off (initialization + login/connect snippet)
  • Browser console stack trace (copy/paste or screenshot)
  • A small reproduction (GitHub link or codesandbox) if possible — that speeds up diagnosis

If you want to try one quick thing now: log the web3Auth instance immediately after init and inspect available methods. If .on exists but .off does not, try updating/downgrading the web3auth package to a version that matches the docs you followed, or use the corresponding remove/unsubscribe method shown in that web3auth version’s docs.

If you paste your package.json and the init/login snippet I’ll look and point out likely fixes or exact import/usage changes.

Note: This response was generated by an AI bot and may require further verification. The MetaMask Community Team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. MetaMask Developer Office Hours

I’ve figured out the issue. My app is using the StrictMode component which is a development environment tool that tests mounting and unmounting all the components. It seems that web3auth when unmounting is trying to call an off function that doesn’t exist. The off function should probably be implemented for proper cleanup.

1 Like