js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

fix: Workaround for ethers.js bug in webpack environments

Open joshdchang opened this issue 1 year ago • 5 comments
trafficstars

Description

I was getting the following issue when trying to connect in a nodejs server-side webpack environment (in Next.js):

Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.7.2)

After doing some searching and testing, I figured out it was an bug from ethers.js with webpack. I tried the workaround from https://github.com/ethers-io/ethers.js/issues/3536#issuecomment-1323302238 and it fixed the issue. This PR only changes one line of code.

Type of change

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [x] Try running it in Next.js server side with and without this change. You will see the difference.

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [x] Any dependent changes have been merged and published in downstream modules

joshdchang avatar Jul 16 '24 21:07 joshdchang

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 16 '24 21:07 CLAassistant

Could you change the JsonRpcProvider to StaticJsonRpcProvider?

We have just got this PR up (#537) which could half to RPC request time by simply changing it to static

Sure let me try

joshdchang avatar Jul 16 '24 21:07 joshdchang

@Ansonhkg Okay I changed it to StaticJsonRpcProvider and it seems to work well.

joshdchang avatar Jul 16 '24 21:07 joshdchang

Are you OK to make that change @joshdchang?

Hi, thanks for this! Do you want me to change it to StaticJSONRPCProvider in all the locations as well? This would overlap substantially with #537 and might lead to merge conflicts. Maybe this is best done in one PR?

joshdchang avatar Jul 22 '24 18:07 joshdchang

Are you OK to make that change @joshdchang?

Hi, thanks for this! Do you want me to change it to StaticJSONRPCProvider in all the locations as well? This would overlap substantially with #537 and might lead to merge conflicts. Maybe this is best done in one PR?

Sorry for the delayed response, and thanks so much for contributing! We've landed the JsonStaticRPCProvider PR now, so you're GTG without needing to worry about conflicts :)

MaximusHaximus avatar Jul 25 '24 18:07 MaximusHaximus

Replacing this with https://github.com/LIT-Protocol/js-sdk/pull/646 which has the changes needed on all the providers. Thanks @joshdchang !!!

FedericoAmura avatar Sep 23 '24 19:09 FedericoAmura