orbitdb / orbitdb

Peer-to-Peer Databases for the Decentralized Web
MIT License
8.32k stars 569 forks source link

Error using OrbitDB #1195

Open ckdiak opened 1 month ago

ckdiak commented 1 month ago

I always get this error when I try to use OrbitDB:

admin@Air-von-Admin src % node index.js 
file:///Users/admin/Projects/Tryvilni/node_modules/@orbitdb/core/src/sync.js:274
      pubsub.addEventListener('subscription-change', handlePeerSubscribed)
             ^

TypeError: Cannot read properties of undefined (reading 'addEventListener')
    at startSync (file:///Users/admin/Projects/Tryvilni/node_modules/@orbitdb/core/src/sync.js:274:14)
    at async Sync (file:///Users/admin/Projects/Tryvilni/node_modules/@orbitdb/core/src/sync.js:284:5)
    at async Database (file:///Users/admin/Projects/Tryvilni/node_modules/@orbitdb/core/src/database.js:188:16)
    at async file:///Users/admin/Projects/Tryvilni/node_modules/@orbitdb/core/src/databases/events.js:19:20
    at async Object.open (file:///Users/admin/Projects/Tryvilni/node_modules/@orbitdb/core/src/orbitdb.js:156:16)
    at async file:///Users/admin/Projects/Tryvilni/src/index.js:8:14

Node.js v22.4.0

This is my code⬇️, but I also get this error when I try to run oribtdb getting started index.js code. What to do?

import { createLibp2p } from 'libp2p'
import { createHelia } from 'helia'
import { createOrbitDB } from '@orbitdb/core'

const libp2p = await createLibp2p({ /* Libp2p options */ })
const ipfs = await createHelia({ libp2p }) // Helia is required for storage and network communication
const orbitdb = await createOrbitDB({ ipfs })
const mydb = await orbitdb.open('mydb')
console.log(mydb.address) // /orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13
await mydb.add("hello world!")
Jon-Biz commented 1 month ago

What version of @chainsafe/libp2p-gossipsub are you using?

Orbitdb doesn't appear to be compatible with @chainsafe/libp2p-gossipsub 14. Specifying ^13.0.0 may resolve your issue.

EDIT: I suspect I may have actually run into a different issue than you, fwiw.

haydenyoung commented 3 weeks ago

Could you please share your libp2p configuration? The error suggests that nothing has been configured for pubsub hence the "undefined" error.

IbexLabsLuk commented 1 week ago

I'm minding my own business, sitting here and bumping versions.

The issue occurs as well when upgrading to helia 5.0 and OrbitDB 2.4.3

{
    addresses: {
      listen: ['/ip4/127.0.0.1/tcp/0/ws'],
    },
    transports: [
      webSockets({
        filter: all,
      }),
    ],
    connectionEncryption: [noise()],
    streamMuxers: [yamux()],
    connectionGater: {
      denyDialMultiaddr: () => true,
    },
    services: {
      identify: identify(),
      pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
    },
  },

Edit:

Last Edit:

haydenyoung commented 1 week ago

admin@Air-von-Admin src % node index.js file:///Users/admin/Projects/Tryvilni/node_modules/@orbitdb/core/src/sync.js:274 pubsub.addEventListener('subscription-change', handlePeerSubscribed)

TypeError: Cannot read properties of undefined (reading 'addEventListener')

The error suggests you don't have any pubsub configuration, hence pubsub is undefined.

haydenyoung commented 1 week ago

I'm minding my own business, sitting here and bumping versions.

The issue occurs as well when upgrading to helia 5.0 and OrbitDB 2.4.3

{
    addresses: {
      listen: ['/ip4/127.0.0.1/tcp/0/ws'],
    },
    transports: [
      webSockets({
        filter: all,
      }),
    ],
    connectionEncryption: [noise()],
    streamMuxers: [yamux()],
    connectionGater: {
      denyDialMultiaddr: () => true,
    },
    services: {
      identify: identify(),
      pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
    },
  },

Edit:

* Previous OrbitDB was 2.2.0, Helia 4.2.3, Libp2p 1.6.1

* New: 2.4.3, 5.1.0 2.2.2

* In this configuration downgrading gossip did not help either.

* Further investigation hints at libp2p encryption / signature configuration.

* Even the helia default createHelia() doesn't work for me.

Last Edit:

* In my case i run a monorepo with multiple packages. A few of them depend upon `@orbitdb/core`

* I checked functionality in the middle of updating package by package.

* Therefore at some point I was using OrbitDB 2.2.0 and 2.4.3 at the same time.

Are you able to provide a way to reproduce the problem?