question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ethers and Rollup

See original GitHub issue

Hello,

I am struggling to get ethers.js to work with rollup.

The specific error that I am encountering in browser is:

Uncaught SyntaxError: The requested module './../../../bn.js/lib/bn.js' does not provide an export named 'default'

Here is a repo to reproduce the error: https://github.com/GradientCap/Graph

Rollup config: https://github.com/GradientCap/Graph/blob/main/rollup.config.js

I’ve tried setting mainfields and using the commonjs plugin configuration from the ethers repo to no avail.

Any help would be appreciated.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
veikkoeevacommented, May 30, 2021

I’ll add here that I did just a quick experiment by going to node_modules and bn.js package where I patched package.config to have "module": "lib/bn.esm.js", created a file with that name and copy-pasted the contents of bn.js to there and echanged the module export to export default { BN } and it compiled. Another idea could something like import BN from "bn.js"; -> import * as _BN from "bn.js"; and doing it to all modules that import like that, but it wouldn’t work on runtime.

There’s more links in the SO thread, but it looks to me RollupJS checks module field and due to recent changed it may be @rollup/plugin-commonjs does not catch the CJS module exports in the files and so consequently they are not transpiled to ESM ones in expeced format.

I am not sure how laborious would it be to turn the file into ES modules locally and add default exports, but maybe I try later next week. Looking quickly at packages, most are maintained by @ricmoo already or have a TS/Rollup builds that just do not provide ES builds yet. 😃 (As an aside, it appears to be web advocates from communities like lit.dev, open-wc etc. note to provide ES6 builds with modern code and let users to transpile if they need specific polyfills etc.)

0reactions
ricmoocommented, Jan 9, 2022

Once the beta of v6 is out, I would love wools to experiment with various bundlers. I personally only use rollup (you can check out the various rollup configs in the project for some ideas if you are having problems) and webpack as part of the ReactNative tests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Are Rollups? ZK Rollups and Optimistic Rollups Explained
Rollups process transactions on another, faster blockchain (known as a ... with ether (ETH) or ERC-20 tokens – tokens that are compliant ...
Read more >
Optimistic Rollups | ethereum.org
An optimistic rollup is an approach to scaling Ethereum that involves moving computation and state storage off-chain. Optimistic rollups execute transactions ...
Read more >
Ethereum: a beginner-ish guide to Rollups | by Raphael Meyer
A basic transfer of Ether cost about $5 in November 2021, while a DeFi transaction (Uniswap for example) can cost more than $100....
Read more >
Contributing and Hacking - ethers
The ethers.js library is something that I've written out of necessity, ... several intermediate builds, scripts and for various rollup scripts to execute....
Read more >
Ethereum Rollups Explained - Liquid Blog
Rollups process all the computational works of a transaction in their ... is and how it can affect the blockchain and the value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found