ethers.js: cloudflare worker fails with some parameters that ethers.js harcode
cloudflare worker mimic the behavior of a service worker, as such it is like a limited browser environment.
unfortunately it does not implement all parameters of the fetch
api making it fails with ethers.js due to these lines:
While the redirect
field works, the other do not and I get a respective error for each:
The 'credentials' field on 'RequestInitializerDict' is not implemented.
The 'cache' field on 'RequestInitializerDict' is not implemented.
The 'mode' field on 'RequestInitializerDict' is not implemented.
The 'referrer' field on 'RequestInitializerDict' is not implemented.
Would be great if we could override the default behavior here.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (7 by maintainers)
Commits related to this issue
- Add support for Cloudflare Workers (#1886). — committed to ethers-io/ethers.js by ricmoo 3 years ago
- Added Cloudflare Worker support (#1886). — committed to ethers-io/ethers.js by ricmoo 2 years ago
- docs: added skipFetchSetup to ConnectionInfo (#1886). — committed to ethers-io/ethers.js by ricmoo 2 years ago
- fix # https://github.com/ethers-io/ethers.js/issues/1886#issuecomment-1063531514 — committed to noplan-inc/entertainment-hackathon by serinuntius a year ago
- Update getFlowRateServerSide.ts Modified the ethers provided to StaticJsonRpcProvider. This issue shows it why. https://github.com/ethers-io/ethers.js/issues/1886 — committed to luisalrp/pocsuperfluidservercomponent by luisalrp 6 months ago
- Added Cloudflare Worker support (#1886). — committed to Woodpile37/ethers.js by ricmoo 2 years ago
- docs: added skipFetchSetup to ConnectionInfo (#1886). — committed to Woodpile37/ethers.js by ricmoo 2 years ago
This is now available in v5.6. I’ve tried it out and am loving Cloudflare Workers.
To use it, connect to your provider setting the
skipFetchSetup
flag:Let me know if you have any issues!
@wighawag Wow, thank you! I am using webpack and this is my webpack config, based on your suggestion:
I needed to install
string-replace-loader
webpack loader and everything worked out of the box, amazing.Thank you @wighawag and thank you @ricmoo for the amazing package.
Yeah, I messed up an didn’t expose it high enough up. I might have to make another minor bump to expose it. I was hoping to get v6 out sooner too though. Let me look into this.
@DanielAGW
as a workaround I perform a post-process step after build :
Note: using esbuild to generate
dist/index.mjs
I think that it has been fixed by @ricmoo but not included in an NPM version.
Ugh. 😦
The problem is allowing them to be overrides would balloon the size of the code, as those would all need non-default behaviours implemented in the node
getUrl
functions.They are the default values, so I am inclined to remove them and let the defaults take over, but that may break something else. I need to investigate this further.
Ideally, Cloudflare would ignore values if they are the default. 😒