Different behaviour when running in Cocos preview VS build in Chrome browser

I’m getting so frustrated with Cocos… I’m getting different behaviour when running in Preview and when running in Chrome browser… if someone could please share their experience on this issue.

I have integrated web3 into Cocos following this tutorial: Building Your First Game dApp On TomoChain (Part 2) | by TomoChain Publisher | TomoChain | Medium

Now I create another custom label and changing its text to the address as follows:

  //Init current account address
  initAccount() {
    this.Web3.eth.getAccounts().then(accounts => {
      if (accounts.length > 0) {
        Web3Controller.instance.CurrentAccount = accounts[0].toLowerCase();
        **Web3Controller.instance.labelll.string = Web3Controller.instance.CurrentAccount;**

} else
          "Error not connected!"

This works fine when running in cocos preview using browser but when I build and host the game it does not update the label with the address. It gives me error:

index.a156f.js:82 Uncaught (in promise) TypeError: Cannot set properties of null (setting 'string')

Why would it work in cocos preview but not when I build the game. This seems like a serious bug to me.

Update on this, I downgraded the project to 2.4.0 and now it seems to work… I think there is a bug with new version of Cocos with regards to this…

Thanks, what version of v3 were you using? I can ask engineering to help.

I was using 2.4.6

Can you provide a simple demo?

Yes please check this example: GitHub - frogdevvn/tomoluckybox-example-cocoscreator

Just check this option.