- Moralis.onAccountsChanged is not a function

Hi. I had a 401 error while fetching NFTs, so one of the solution said I had to update react, reac-moralis and moralis. I did and I ended up with this:

TypeError: Moralis.onAccountsChanged is not a function
(anonymous function)
src/providers/MoralisDappProvider/MoralisDappProvider.js:14
  11 |   setChainId(chain);
  12 | });
  13 | 
> 14 | Moralis.onAccountsChanged(function (address) {
     | ^  15 |   setWalletAddress(address[0]);
  16 | });
  17 | // eslint-disable-next-line react-hooks/exhaustive-deps

TypeError: Moralis.onAccountsChanged is not a function
(anonymous function)
src/providers/MoralisDappProvider/MoralisDappProvider.js:14
  11 |   setChainId(chain);
  12 | });
  13 | 
> 14 | Moralis.onAccountsChanged(function (address) {
     | ^  15 |   setWalletAddress(address[0]);
  16 | });
  17 | // eslint-disable-next-line react-hooks/exhaustive-deps

Console logs:

./node_modules/magic-sdk/dist/es/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/magic-sdk/dist/es/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/moralis/lib/browser/Web3Connector/Web3AuthConnector.js
Module not found: Can’t resolve ‘@web3auth/web3auth’ in ‘/home/lautaro/nft/ethereum-boilerplate/node_modules/moralis/lib/browser/Web3Connector’

There is a post about this error but it isn’t clear how to solve it.

I think that it is a solution presented here:

I solved the “onaccountschanged”, it was just deleting the ‘s’. But I’m still getting “TypeError: Cannot read properties of null (reading ‘provider’)”. Also, how do you implement the “Moralis.enableWeb3();” with ‘await’ outside a function? I tried wrapping it inside an async function but I’m not sure if it’s working.

1 Like

The web3 const you define, what do you do with it? Should those two lines go in the index or in the MoralisDappProvider? I tried to implement them on this last one, but I get that Web3 is not defined (even if I just imported it).

you can create a new thread with details of the problem that you have