Skip to content

wasm-pack build fails for WebRTC + gossipsub in libp2p v0.56.0 due to ahash → getrandom v0.3.4 #6246

@fgtest1

Description

@fgtest1

Summary

When building a WASM P2P node with gossipsub and webrtc-websys in libp2p v0.56.0, the build fails due to an unresolved getrandom backend requirement, even though all correct features are enabled.

This blocks browser-to-browser gossipsub in WASM until either:

  • The ahash dependency is fully removed from gossipsub, or
  • Proper WebRTC transport APIs are exposed in SwarmBuilder.

Steps to Reproduce

  1. Create a minimal WASM crate with:
    [dependencies.libp2p]
    version = "0.56.0"
    default-features = false
    features = [
      "webrtc-websys",
      "noise",
      "wasm-bindgen",
      "gossipsub"
    ]
    
    
  2. Implement a basic NetworkBehaviour with gossipsub::Behaviour
  3. Try to build with:wasm-pack build --target web
    4.Expected Behavior
    Compiles successfully (as implied by docs and examples)
    WebRTC transport works via .with_webrtc() or equivalent

Actual Behavior
Error 1: Missing .with_webrtc() method
error[E0599]: no method named with_webrtc found for struct SwarmBuilder<...>

Error 2: getrandom v0.3.4 fails in WASM

This happens because:

libp2p-gossipsub v0.49.2 → hashlink → hashbrown → ahash → getrandom v0.3.4
ahash does not enable the wasm_js feature on its getrandom dependency
Even if I add getrandom = { version = "0.3.4", features = ["wasm_js"] },
Cargo doesn’t propagate the feature to transitive deps

Workarounds Tried
✅ Removing gossipsub → compiles (but loses pubsub)
✅ Using websocket-websys instead → works, but requires relay
❌ Adding "serde" or "other" features → doesn’t fix missing .with_webrtc()
❌ Patching getrandom → fails due to ahash hard dependency

Environment
libp2p version: 0.56.0
Rust version: rustc 1.83.0 (or latest stable)
Target: wasm32-unknown-unknown
OS: Windows 11 (but reproducible on Linux/macOS)

Additional Context
PR #5098 replaced ahash with fxhash, which should fix the getrandom issue
However, v0.56.0 still uses ahash, and there’s no published version with the fix
Also, the WebRTC transport API (SwarmBuilder::with_webrtc()) appears to be missing or unstable

Request
Release v0.57.0 with the ahash → fxhash migration (from #5098)
Document the correct way to use WebRTC in WASM — current examples reference .with_webrtc(), but it doesn’t exist in v0.56.0
Clarify whether gossipsub is truly WASM-compatible today

Thank you for your work on libp2p

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions