Replies: 1 comment 3 replies
-
It should work fine if you use the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Ethers Version
5.6.9
Search Terms
module fetch
Describe the Problem
Hey man,
We've been trying to use ethers in a LambdaFunction to make a simple API call to alchemy in order to retrieve the latest block number on the blockchain:
We use esbuild to bundle our apps with
mainFields: ['module', 'main']
so we check for ESM first and then fallback to CJS. We had to create a polyfill containing node-fetch to avoid aReferenceError: fetch is not defined
, but even then, when the lambda containing this snippet is triggered, the following error appears in the logs:We have found two solutions to solve this problem:
mainFields: ['main', 'module']
in order to prioritize CJS, which makes our bundle un-treeshakable (which is bad for us)"module": "./lib.esm/index.js,"
) from the file@ethersproject/web/package.json
.The reason we think the problem is happening is the use of browser's
fetch
(and maybe other browser native functions) in@ethersproject/web
's module. From reading other issues such as #3165 and #3158, I would guess that a fix is planned for v6 of ethers, but I'm still opening this issue in case there is a cleaner workaround. Tell me what you think about it 🙂Code Snippet
No response
Contract ABI
No response
Errors
No response
Environment
node.js (v12 or newer)
Environment (Other)
No response
Beta Was this translation helpful? Give feedback.
All reactions