Typescript Error when following migration guide

Running into a strange typing issue when trying to ugprade libp2p from 0.39.5 to 0.40 in farcaster/hubble. This also occurs with the sample code in the migration guide shown below, so it’s likely something to do with conflicting dependencies.

Sample code that causes the error:

import { createLibp2p } from 'libp2p'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { mdns } from '@libp2p/mdns'
import { noise } from '@chainsafe/libp2p-noise'
import { mplex } from '@libp2p/mplex'


const node = await createLibp2p({
  peerDiscovery: [
    mdns(),
  ],
  connectionEncryption: [
    noise()
  ],
  streamMuxers: [
    mplex()
  ],
  pubsub: gossipsub()
})

The trace of the error:

Type '() => ConnectionEncrypter<NoiseExtensions>' is not assignable to type '(components: Components) => ConnectionEncrypter<unknown>'.
  Call signature return types 'ConnectionEncrypter<NoiseExtensions>' and 'ConnectionEncrypter<unknown>' are incompatible.
    The types of 'secureOutbound' are incompatible between these types.
      Type '(localPeer: import("/Users/varun/src/farcaster/hubble/node_modules/@libp2p/interface-peer-id/dist/src/index").PeerId, connection: import("/Users/varun/src/farcaster/hubble/node_modules/it-stream-types/dist/src/index").Duplex<Uint8Array, Uint8Array, Promise<...>>, remotePeer?: import("/Users/varun/src/farcaster/hubbl...' is not assignable to type '(localPeer: import("/Users/varun/src/farcaster/hubble/node_modules/libp2p/node_modules/@libp2p/interface-connection-encrypter/node_modules/@libp2p/interface-peer-id/dist/src/index").PeerId, connection: import("/Users/varun/src/farcaster/hubble/node_modules/it-stream-types/dist/src/index").Duplex<...>, remotePeer?: i...'.
        Types of parameters 'localPeer' and 'localPeer' are incompatible.
          Type 'import("/Users/varun/src/farcaster/hubble/node_modules/libp2p/node_modules/@libp2p/interface-connection-encrypter/node_modules/@libp2p/interface-peer-id/dist/src/index").PeerId' is not assignable to type 'import("/Users/varun/src/farcaster/hubble/node_modules/@libp2p/interface-peer-id/dist/src/index").PeerId'.
            Type 'RSAPeerId' is not assignable to type 'PeerId'.
              Type 'import("/Users/varun/src/farcaster/hubble/node_modules/libp2p/node_modules/@libp2p/interface-connection-encrypter/node_modules/@libp2p/interface-peer-id/dist/src/index").RSAPeerId' is not assignable to type 'import("/Users/varun/src/farcaster/hubble/node_modules/@libp2p/interface-peer-id/dist/src/index").RSAPeerId'.
                The types returned by 'toCID().toV0().toJSON()' are incompatible between these types.
                  Type '{ '/': ToString<CID<unknown, 112, 18, 0>, string>; }' is missing the following properties from type '{ code: 112; version: 0; hash: Uint8Array; }': code, version, hashts(2322)

Packages currently installed;

@chainsafe/libp2p-gossipsub   5.0.0              5.4.1              6.1.0    @farcaster/hubble dependencies    https://github.com/ChainSafe/js-libp2p-gossipsub#readme
@chainsafe/libp2p-noise       10.0.1             10.0.1             11.0.0   @farcaster/hubble dependencies    https://github.com/ChainSafe/js-libp2p-noise#readme
@libp2p/interface-connection  3.0.6              3.0.8              3.0.8    @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-connection#readme
@libp2p/interface-mocks       8.0.0              8.0.0              9.1.1    @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-mocks#readme
@libp2p/interface-peer-id     1.1.2              1.1.2              2.0.1    @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-peer-id#readme
@libp2p/mplex                 7.0.0              7.0.0              7.1.1    @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p-mplex#readme
@libp2p/peer-id-factory       1.0.20             1.0.20             2.0.1    @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p-peer-id/tree/master/packages/libp2p-peer-id-factory#readme
@libp2p/pubsub-peer-discovery 7.0.0              7.0.0              8.0.0    @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p-pubsub-peer-discovery#readme
@libp2p/tcp                   6.0.0              6.0.0              6.1.2    @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p-tcp#readme
@multiformats/multiaddr       11.1.4             11.4.0             11.4.0   @farcaster/hubble dependencies    https://github.com/multiformats/js-multiaddr#readme
libp2p                        0.40.0             0.40.0             0.42.2   @farcaster/hubble dependencies    https://github.com/libp2p/js-libp2p#readme

There are multiple versions of multiformats in your dependency tree. The easiest way to fix this is to ensure you’re using the latest version of all dependencies - that’s libp2p@0.42.x at the time of writing.

If you cannot upgrade to the latest version, please check the package.json of libp2p at the time of the release you are trying to upgrade to.

If you can only go as far as libp2p@0.40.x, the package.json of libp2p@0.40.x suggests you need @chainsafe/libp2p-noise@9.x.x - I think you have 10.x.x above: js-libp2p/package.json at v0.40.0 Β· libp2p/js-libp2p Β· GitHub

I noticed that 0.40.x includes noise@9.x.x in the package.json.

However, the migration guide assumes that noise is initialized with constructor injection, but that doesn’t happen till noise@10.x according to the changelog here.

Rolling back to 9.x.x and attempting to initialize with new Noise() returns the error:

Type 'Noise' is not assignable to type '(components: Components) => ConnectionEncrypter<unknown>'.
  Type 'Noise' provides no match for the signature '(components: Components): ConnectionEncrypter<unknown>'.ts(2322)

I will try jumping straight to 0.42.x and see if that resolves the dependency tree issues

I think something like this would help greatly here: Generate a markdown table of ecosystem module versions Β· Issue #1182 Β· ipfs/aegir Β· GitHub

1 Like

Unfortunately, I’m running into the same typing issue with noise() when jumping to 0.42.x.

I tried upgrading all the packages to the versions specified in the package.json. There are two packages I’m using missing from package.json: @chainsafe/libp2p-gossipsub and libp2p/pubsub-peer-discovery. I just upgraded to the latest versions I could find.

I’ve added the full dependency list below in case it is helpful for debugging:

(base) ➜  hubble git:(varunsrin/libp2p-0.40) βœ— yarn list --pattern "libp2p|multi"
yarn list v1.22.19
β”œβ”€ @chainsafe/libp2p-gossipsub@6.1.0
β”‚  β”œβ”€ @libp2p/crypto@1.0.7
β”‚  β”‚  β”œβ”€ @libp2p/interface-keys@1.0.6
β”‚  β”‚  └─ multiformats@10.0.3
β”‚  β”œβ”€ @libp2p/interface-connection-manager@1.3.7
β”‚  β”‚  └─ @libp2p/interfaces@3.1.0
β”‚  β”œβ”€ @libp2p/interface-keys@1.0.3
β”‚  └─ @libp2p/interfaces@3.3.1
β”œβ”€ @chainsafe/libp2p-noise@11.0.0
β”œβ”€ @farcaster/hubble@1.0.5
β”‚  β”œβ”€ @libp2p/interface-connection@3.0.6
β”‚  β”‚  └─ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/crypto@1.0.10
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-address-manager@2.0.4
β”œβ”€ @libp2p/interface-connection-encrypter@3.0.1
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-connection-manager@1.3.0
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-connection@3.0.2
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-content-routing@2.0.1
β”œβ”€ @libp2p/interface-dht@2.0.1
β”œβ”€ @libp2p/interface-keychain@2.0.4
β”œβ”€ @libp2p/interface-keys@1.0.6
β”œβ”€ @libp2p/interface-libp2p@1.1.1
β”‚  β”œβ”€ @libp2p/interface-peer-routing@1.0.7
β”‚  └─ @libp2p/interface-peer-store@1.2.8
β”œβ”€ @libp2p/interface-metrics@4.0.5
β”œβ”€ @libp2p/interface-mocks@9.1.1
β”œβ”€ @libp2p/interface-peer-discovery@1.0.1
β”œβ”€ @libp2p/interface-peer-id@2.0.1
β”œβ”€ @libp2p/interface-peer-info@1.0.6
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-peer-routing@1.0.1
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-peer-store@1.2.2
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-pubsub@3.0.6
β”œβ”€ @libp2p/interface-record@2.0.4
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-registrar@2.0.3
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/interface-stream-muxer@3.0.0
β”œβ”€ @libp2p/interface-transport@2.0.0
β”œβ”€ @libp2p/interfaces@3.1.0
β”œβ”€ @libp2p/logger@2.0.2
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/mplex@7.1.1
β”œβ”€ @libp2p/multistream-select@3.1.0
β”‚  └─ @libp2p/interfaces@3.0.3
β”œβ”€ @libp2p/peer-collections@3.0.0
β”œβ”€ @libp2p/peer-id-factory@2.0.1
β”œβ”€ @libp2p/peer-id@2.0.1
β”‚  └─ @libp2p/interfaces@3.3.1
β”œβ”€ @libp2p/peer-record@5.0.0
β”‚  β”œβ”€ @libp2p/crypto@1.0.11
β”‚  β”œβ”€ @libp2p/interface-connection@3.0.6
β”‚  β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  β”‚  └─ multiformats@10.0.3
β”‚  β”œβ”€ @libp2p/interface-peer-store@1.2.6
β”‚  β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  β”‚  β”œβ”€ @libp2p/interface-record@2.0.4
β”‚  β”‚  └─ multiformats@10.0.3
β”‚  β”œβ”€ @libp2p/interface-record@2.0.1
β”‚  β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  β”‚  └─ multiformats@10.0.3
β”‚  β”œβ”€ @libp2p/logger@2.0.5
β”‚  └─ @libp2p/utils@3.0.2
β”‚     β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚     β”œβ”€ @libp2p/logger@2.0.2
β”‚     └─ multiformats@10.0.3
β”œβ”€ @libp2p/peer-store@6.0.0
β”‚  └─ @libp2p/interface-record@2.0.1
β”‚     β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚     └─ multiformats@10.0.3
β”œβ”€ @libp2p/pubsub-peer-discovery@8.0.0
β”‚  β”œβ”€ @libp2p/interface-peer-info@1.0.3
β”‚  β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  β”‚  β”œβ”€ @multiformats/multiaddr@11.1.4
β”‚  β”‚  └─ multiformats@10.0.3
β”‚  └─ @multiformats/multiaddr@11.4.0
β”œβ”€ @libp2p/pubsub@6.0.1
β”‚  └─ @libp2p/interfaces@3.3.1
β”œβ”€ @libp2p/tcp@6.1.2
β”‚  β”œβ”€ @libp2p/interface-connection@3.0.6
β”‚  β”‚  └─ @libp2p/interfaces@3.1.0
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  β”œβ”€ @libp2p/interfaces@3.3.1
β”‚  └─ multiformats@10.0.3
β”œβ”€ @libp2p/topology@4.0.1
β”œβ”€ @libp2p/tracked-map@3.0.2
β”œβ”€ @libp2p/utils@3.0.4
β”‚  β”œβ”€ @libp2p/interface-connection@3.0.6
β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  β”œβ”€ @libp2p/interface-peer-store@1.2.6
β”‚  └─ multiformats@10.0.3
β”œβ”€ @multiformats/mafmt@11.0.3
β”œβ”€ @multiformats/multiaddr@11.1.4
β”‚  └─ multiformats@10.0.3
β”œβ”€ libp2p@0.42.2
β”‚  β”œβ”€ @libp2p/crypto@1.0.7
β”‚  β”‚  └─ multiformats@10.0.3
β”‚  β”œβ”€ @libp2p/interface-connection-encrypter@3.0.6
β”‚  β”œβ”€ @libp2p/interface-connection@3.0.6
β”‚  β”‚  β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚  β”‚  └─ multiformats@10.0.3
β”‚  └─ @libp2p/interface-transport@2.1.1
β”‚     β”œβ”€ @libp2p/interface-connection@3.0.2
β”‚     β”œβ”€ @libp2p/interface-peer-id@1.1.2
β”‚     └─ multiformats@10.0.3
β”œβ”€ multiformats@11.0.1
└─ uint8arrays@4.0.2
   └─ multiformats@10.0.3
✨  Done in 0.22s.

You still have multiple versions of multiformats in your dependency tree.

I see for example:

β”œβ”€ multiformats@11.0.1
└─ uint8arrays@4.0.2
   └─ multiformats@10.0.3

You depend directly on multiformats@11.0.1 and uint8arrays@4.0.2.

uint8arrays@4.0.2 has a dependency on multiformats@10.0.3.

uint8arrays@4.0.3 OTOH has a dependency on multiformats@11.0.0.

Do you have a lockfile? Have you tried deleting it?

managed to get it working by both upgrading to the packages listed in 0.42.2 and blowing away lockfile. thanks for the help.

blowing away lockfile with a lower version (0.40.0) still caused the same issue unfortunately.

1 Like