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

Example codes do not work #1820

Closed
1 task done
HoseinHaqiqian opened this issue Jun 14, 2023 · 4 comments
Closed
1 task done

Example codes do not work #1820

HoseinHaqiqian opened this issue Jun 14, 2023 · 4 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@HoseinHaqiqian
Copy link

HoseinHaqiqian commented Jun 14, 2023

  • Version: 0.45.6
  • Platform: Mac os M1
  • Node version: v19.6.0
  • Npm version: 9.4.0

Severity: High

Description:

  • What you did :

  • i executed one of the example codes with node 1.js command

  • What happened :

it failed with following error : Cannot find module ..../llibp2p/dist/src/index.js improted from ..../js-libp2p/examples/peer-and-content-routing/1.js

  • What you expected to happen :

run successfully

@HoseinHaqiqian HoseinHaqiqian added the need/triage Needs initial labeling and prioritization label Jun 14, 2023
@HoseinHaqiqian HoseinHaqiqian changed the title Example codes does not work Example codes do not work Jun 14, 2023
@HoseinHaqiqian
Copy link
Author

After creating project with latest version of libp2p, it gives me following error :
Command : ts-node --esm index.ts

Error : No "exports" main defined in project_path/node_modules/libp2p/package.json

@greenSnot
Copy link
Contributor

dht from the example should be moved to peerRouters: [kadDHT()]?

const node = await createLibp2p({
    addresses: {
      listen: ['/ip4/0.0.0.0/tcp/0']
    },
    transports: [tcp()],
    streamMuxers: [yamux(), mplex()],
    connectionEncryption: [noise()],
    dht: kadDHT()
  })

@achingbrain
Copy link
Member

There are a few different issues here.

it failed with following error : Cannot find module ..../llibp2p/dist/src/index.js improted from ..../js-libp2p/examples/peer-and-content-routing/1.js

This is because you need to build the monorepo first.

$ git clone https://....
$ cd libp2p
$ npm i && npm run build
$ cd example/foo
$ node 1.js

After creating project with latest version of libp2p, it gives me following error :
Command : ts-node --esm index.ts

Error : No "exports" main defined in project_path/node_modules/libp2p/package.json

Please see discussion in #1583 but the TLDR is that ts-node doesn't support ESM yet.

dht from the example should be moved to peerRouters: [kadDHT()]?

No, the KAD-DHT implementation should be in the services map, though it's unrelated to the above issues..

@HoseinHaqiqian
Copy link
Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
Archived in project
Development

No branches or pull requests

3 participants