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

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

Open
codeicey opened this issue Dec 26, 2024 · 1 comment

Comments

@codeicey
Copy link

I was trying out second usage in liftoff docs and ran into this error:

Steps to reproduce

`
import { createOrbitDB } from "@orbitdb/core";
import { createLibp2p } from "libp2p";
import { createHelia } from "helia";
import { DefaultLibp2pOptions } from "@orbitdb/liftoff";

const libp2p = createLibp2p({ ...DefaultLibp2pOptions });
const ipfs = await createHelia({ libp2p });

const orbitdb = await createOrbitDB({ ipfs });

const db1 = await orbitdb.open("db1");
await db1.add("hello world!");
console.log(await db1.all());
`

Error log

`
file:///home/runner/orbit/node_modules/@orbitdb/core/src/sync.js:276
pubsub.addEventListener('subscription-change', handlePeerSubscribed)
^

TypeError: Cannot read properties of undefined (reading 'addEventListener')
at startSync (file:///home/runner/orbit/node_modules/@orbitdb/core/src/sync.js:276:14)
at async Sync (file:///home/runner/orbit/node_modules/@orbitdb/core/src/sync.js:286:5)
at async Database (file:///home/runner/orbit/node_modules/@orbitdb/core/src/database.js:188:16)
at async file:///home/runner/orbit/node_modules/@orbitdb/core/src/databases/events.js:19:20
at async Object.open (file:///home/runner/orbit/node_modules/@orbitdb/core/src/orbitdb.js:156:16)
at async file:///home/runner/orbit/index.js:11:13

Node.js v20.18.1
`

Package.json and IDE

IDE: Replit

Package.json

`
{
"name": "nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"type": "module",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@orbitdb/core": "^2.4.1",
"@orbitdb/liftoff": "^1.1.0",
"@types/node": "^18.0.6",
"helia": "^5.1.0",
"libp2p": "^2.4.2"
}
}

`

@haydenyoung
Copy link
Member

It looks like pubsub isn't available because there is a missing await when calling createLibp2p.

Update the following line and it should work as expected:

const libp2p = await createLibp2p({ ...DefaultLibp2pOptions })

The usage docs have been updated to reflect this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants