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

Package path . is not exported from package /home/.../node_modules/libp2p #1776

Closed
reubenfirmin opened this issue May 26, 2023 · 5 comments
Closed
Labels
need/triage Needs initial labeling and prioritization

Comments

@reubenfirmin
Copy link

reubenfirmin commented May 26, 2023

I cannot get to the hello world point with https://github.com/libp2p/js-libp2p/blob/master/doc/GETTING_STARTED.md.

rm -fr node_modules/
npm install
npm install libp2p
npm install @libp2p/websockets
npm run build

This yields an error:

Module not found: Error: Package path . is not exported from package /home/.../node_modules/libp2p (see exports field in /home/.../node_modules/libp2p/package.json)

It set up package.json with:

  "dependencies": {
    "@libp2p/websockets": "^6.0.1",
    "libp2p": "^0.45.4"
  },

My code is (typescript):

import { createLibp2p } from 'libp2p';
import {webSockets} from "@libp2p/websockets";

export class PeerSyncer {

    constructor(private identity: any) {}

    async start(): Promise<void> {

        const libp2p = await createLibp2p({
            // addresses: {
            //     listen: ['/ip4/0.0.0.0/tcp/0', '/ip4/0.0.0.0/tcp/0/ws']
            // },
            // transports: [webSockets()]
        });
    }
}

Commenting out the call to createLibp2p allows it to build, presumably because the tree shaker gets rid of the import.

npm --version
9.6.5
@reubenfirmin reubenfirmin added the need/triage Needs initial labeling and prioritization label May 26, 2023
@maschad
Copy link
Member

maschad commented May 29, 2023

Could you share your tsconfig.json and the node version as well? We define the export types here

@reubenfirmin
Copy link
Author

tsconfig:

{
  "compilerOptions": {
    "strict": true,
    "module": "commonjs",
    "target": "es6",
    "esModuleInterop": true,
    "sourceMap": true,
    "rootDir": "src",
    "outDir": "dist/js",
    "noEmitOnError": true,
    "typeRoots": [ "node_modules/@types" ],
    "jsx": "react"
  }
}
node --version
v18.16.0

@achingbrain
Copy link
Member

"module": "commonjs",
"target": "es6"

libp2p is an ESM-only module, this configuration option uses the wrong module system - please change it to use ESM:

{
  "compilerOptions": {
    "module": "ES2022",
    "esModuleInterop": true,
    "target": "ES2022",
    "moduleResolution": "node"
  }
}

@reubenfirmin
Copy link
Author

@achingbrain OK, can you specify that in getting started then?

https://github.com/libp2p/js-libp2p/blob/master/doc/GETTING_STARTED.md

@maschad
Copy link
Member

maschad commented May 31, 2023

@achingbrain OK, can you specify that in getting started then?

master/doc/GETTING_STARTED.md

Good suggestion I created a PR #1782 to address that.

maschad added a commit to maschad/js-libp2p that referenced this issue Jun 1, 2023
achingbrain added a commit that referenced this issue Jun 19, 2023
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
None yet
Development

No branches or pull requests

3 participants