You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I thought to add that I see this same error. Project (currently) at https://github.com/veikkoeeva/erc1155sample/ and a few ways of seeing it are running npm run test or npm run start (in console log).
At least my case may be because bn.js seem to be a UMD module whereas Rollupjs by default tries to export ES modules. I wonder if there's something about the TS types over bn.js or something in the https://open-wc.org/guides/ basic set-up. I need to dig a bit deeper to be sure, though.
Here is also a screenshot of one variation of the issue
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.)
It may be possible to refactor bn.js so Rollup understands to transform it to ESM or refactor it to support ESM altogether.
I indeed read from discussion that version 6 would fix this issue one way or another. I do not know if there is a plan to gather around people to test and/or help to expedite version 6 release to fix this.
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.
Activity
ricmoo commentedon Dec 1, 2020
Can you try dropping the
"browser"from your mainFields?samsends commentedon Dec 3, 2020
@ricmoo Hey I tried dropping browser to no avail. Have you seen anything like this before?
ricmoo commentedon Dec 3, 2020
I have seen it before, but haven’t in a while.
What version of rollup.js and version of ethers are you using?
If you are using an older rollup, you maybe need to pass in an
exportskey to the commonjs plug-in?samsends commentedon Dec 8, 2020
Using the latest version of rollup. I'm new to JS / rollup where do you think I should start to debug this?
samsends commentedon Dec 8, 2020
I've tried using some of the rollup configs in the repo which didn't work
veikkoeeva commentedon May 27, 2021
I thought to add that I see this same error. Project (currently) at https://github.com/veikkoeeva/erc1155sample/ and a few ways of seeing it are running
npm run testornpm run start(in console log).At least my case may be because
bn.jsseem to be a UMD module whereas Rollupjs by default tries to export ES modules. I wonder if there's something about the TS types over bn.js or something in the https://open-wc.org/guides/ basic set-up. I need to dig a bit deeper to be sure, though.Here is also a screenshot of one variation of the issue
EDIT: I went over to SO ask too, at https://stackoverflow.com/questions/67728084/transforming-umd-modules-to-es-modules-in-rollupjs-the-requested-module-x-does.
EDIT 2: Made further progress that may help solving this manually by patching files in
node_modules. I'm a bit puzzled though why doesn't Rollup do this already as I think it could. So posted another question at SO, I provide it here just in case: https://stackoverflow.com/questions/67754327/automating-umd-export-to-esm-import-in-rollups.There seem to be a similar case in Rollup repo at rollup/rollup#3994.
veikkoeeva commentedon May 30, 2021
I'll add here that I did just a quick experiment by going to
node_modulesandbn.jspackage where I patchedpackage.configto have"module": "lib/bn.esm.js", created a file with that name and copy-pasted the contents ofbn.jsto there and echanged the module export toexport default { BN }and it compiled. Another idea could something likeimport 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
modulefield and due to recent changed it may be@rollup/plugin-commonjsdoes 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.)
veikkoeeva commentedon Jun 8, 2021
Maybe related development in TS compiler: microsoft/TypeScript#44501.
N00bBot commentedon Oct 23, 2021
I'm having this exact issue as well, did anyone ever come to a solution that doesnt require manual changes to the package?
veikkoeeva commentedon Nov 28, 2021
Maybe useful to know #2203 (comment) .
syffs commentedon Jan 7, 2022
I'm having a similar issue:
@veikkoeeva @samsends did you find any workaround ?
@ricmoo I tried a bunch of ideas I found out there without any luck, like
mainFields: [ "module", "browser", "main" ]instead ofbrowser: true@rollup/plugin-commonjsnameExports is not referenced as an option anymore but still in the doc rollup/rollup#4342If i understand well, v6 is expected to fix this ?
veikkoeeva commentedon Jan 9, 2022
@syffs Only the one I noted in Vite issue forums to set up a patch-package to automate the quick fix I did manually and apply it to all these problems. It may be someone has done it already.
It may be possible to refactor bn.js so Rollup understands to transform it to ESM or refactor it to support ESM altogether.
I indeed read from discussion that version 6 would fix this issue one way or another. I do not know if there is a plan to gather around people to test and/or help to expedite version 6 release to fix this.
<edit: One option is probably also compile and import ethers related parts as "umd" module using Rollup. With a very quick five seconds search engine something like https://remarkablemark.org/blog/2019/07/12/rollup-commonjs-umd/, i.e. a separate entry to generate an Etherjs bundle and then importing it with something like https://stackoverflow.com/questions/51461723/import-umd-javascript-modules-into-browser. In fact I may try to do that within a month if no one else does (just so busy atm :D).
ricmoo commentedon 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.