Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libp2p package is not working with Bun #3877

Closed
ansarizafar opened this issue Jul 29, 2023 · 5 comments
Closed

libp2p package is not working with Bun #3877

ansarizafar opened this issue Jul 29, 2023 · 5 comments
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@ansarizafar
Copy link

What version of Bun is running?

0.7.1

What platform is your computer?

Linux 5.19.0-50-generic x86_64 x86_64

What steps can reproduce the bug?

I have installed libp2p, @libp2p/webtransport, @chainsafe/libp2p-noise packages with bun add command and I am trying to run following code with bun run index.js command

import { createLibp2p } from 'libp2p'
import { webTransport } from '@libp2p/webtransport'
import { noise } from '@chainsafe/libp2p-noise'

const node = await createLibp2p({
  transports: [webTransport()],
  connectionEncryption: [noise()],
 
})

// start libp2p
  await node.start()
  console.log('libp2p has started')

  // print out listening addresses
  console.log('listening on addresses:')
  node.getMultiaddrs().forEach((addr) => {
    console.log(addr.toString())
  })

  // stop libp2p
  await node.stop()
  console.log('libp2p has stopped')

What is the expected behavior?

Code is working with Nodejs and it should run without error with Bun

What do you see instead?

Error message

  origin[keys[i]] = add[keys[i]];
344 |   return origin;
345 | }, kCustomPromisifiedSymbol = Symbol.for("util.promisify.custom"), promisify = function promisify2(original) {
346 |   if (typeof original !== "function")
347 | 
348 |     throw new TypeError('The "original" argument must be of type Function');
             ^
TypeError: The "original" argument must be of type Function
      at promisify2 (node:util:348:10)
      at /home/zafaransari/projects/p2p/node_modules/@libp2p/crypto/dist/src/keys/ed25519.js:5:16

Additional information

No response

@ansarizafar ansarizafar added the bug Something isn't working label Jul 29, 2023
@Electroid Electroid added the node.js Compatibility with Node.js APIs label Jul 30, 2023
@Electroid
Copy link
Contributor

Looks like this is because Bun is missing support for a Node.js feature: https://nodejs.org/api/util.html#custom-promisified-functions

@sirenkovladd
Copy link
Contributor

Also in /node_modules/@libp2p/crypto/dist/src/keys/ed25519.js:5:16

const keypair = promisify(crypto.generateKeyPair);

Bun, doesn't support crypto.generateKeyPair yet, I'll look into that

@efossvold
Copy link

efossvold commented Sep 12, 2023

Any update on this? Having a similar issue on Bun 1.0.1 with the following code.

import { createGrpcTransport } from '@bufbuild/connect-node'

createGrpcTransport({
  httpVersion: '2',
  baseUrl: 'http://127.0.0.1:8080',
})

∨∨∨

361 |   while (i--)
362 |     origin[keys[i]] = add[keys[i]];
363 |   return origin;
364 |
365 | }, kCustomPromisifiedSymbol = Symbol.for("util.promisify.custom"), promisify = function promisify2(original) {

@efossvold
Copy link

I've never used libp2p, but a quick glance at the specs says it uses protobuf to describe the protocols used.

The protocols described below all use protocol buffers (aka protobuf) to define message schemas.

So possibly there's some gRPC in there which is built on top of HTTP2. According this this comment (in #4414), Bun does not support HTTP2 yet, which also explains why the code in my previous comment doesn't work as it uses @bufbuild/connect-node, a gRPC lib.

@Electroid
Copy link
Contributor

Duplicate of #5122

@Electroid Electroid marked this as a duplicate of #5122 Oct 27, 2023
@Electroid Electroid closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants