Closed mshakeg closed 1 year ago
lib/keccak.js
file to use class syntax instead of the old function-class syntax? If that works, then the problem is caused by bun
's inability to support old JS syntax.This sounds like an issue with bun
Keep in mind that this library only supports NodeJS and the browser. bun
is responsible for making sure they can run valid JavaScript and valid NodeJS native modules.
@junderw thanks for the quick reply. To answer your questions:
keccak
, it was installed as a dependency of hardhatkeccak
you are using.@junderw
keccak@3.0.3
was installednode_modules/.pnpm/keccak@3.0.3/node_modules/keccak: Running install script, done in 6.3s
It looks like require('node-gyp-build')(__dirname)
is broken and returns an empty object {}
whereas in NodeJS it returns a function.
https://github.com/cryptocoinjs/keccak/blob/cacd3a529d8477149f2b75284a7d77302e58aa00/bindings.js#L1
Perhaps bun doesn't support N-API native add-ons?
Let me check...
Answer: It does not support N-API, yet.
https://github.com/oven-sh/bun/issues/158
One solution is to import the JS version directly. (this is difficult because it's not your direct dependency)
import createKeccakHash from "keccak/js.js";
Another fix would be on our side. We can fall back to JS when native bindings don't load a function.
I've opened up #28 but unfortunately I don't have publish rights to NPM. I only have merge rights to GitHub.
So we'll have to wait for someone with NPM publish rights to merge and publish.
We published a workaround in 3.0.4
bun shouldn't crash anymore for keccak.
In hardhat specifically, they use ^3.0.2
which will pull in 3.0.4
automatically.
I initially tried to run a script in a hardhat project using bun, however, that failed as explained in NomicFoundation/hardhat/issues/4383
@schaable pointed out that the issue was with this dependency package as
createKeccakHash("keccak256")
throws the following error: