`webrtc` transport breaks compilation for WASM even if it not specified in transports
@sukunrt is already working on this.
Since Aug 12, 2025.
- Dominant language
- Go
- Stars
- 6.9k
- Forks
- 1.3k
- Avg merge
- 13d 21h
- Merged PRs (30d)
- 1
Description
Currently if you try to compile the most basic libp2p host with 0 transports and no listeners like this:
```go
package main
import (
"log"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/p2p/security/noise"
)
func main() {
priv, _, err := crypto.GenerateKeyPair(
crypto.Ed25519,
-1,
)
if err != nil {
panic(err)
}
if err != nil {
panic(err)
}
h2, err := libp2p.NewWithoutDefaults(
libp2p.Identity(priv),
libp2p.NoListenAddrs,
libp2p.Security(noise.ID, noise.New),
libp2p.NoTransports,
)
if err != nil {
panic(err)
}
defer h2.Close()
}
```
it will fail during compilation:
```
GOOS=js GOARCH=wasm go build
# github.com/libp2p/go-libp2p/p2p/transport/webrtc
/home/v1rtl/go/pkg/mod/github.com/libp2p/go-libp2p@v0.41.1/p2p/transport/webrtc/connection.go:109:12: pc.SCTP().OnClose undefined (type *webrtc.SCTPTransport has no field or method OnClose)
/home/v1rtl/go/pkg/mod/github.com/libp2p/go-libp2p@v0.41.1/p2p/transport/webrtc/listener.go:68:35: config.Certificates undefined (type webrtc.Configuration has no field or method Certificates)
/home/v1rtl/go/pkg/mod/github.com/libp2p/go-libp2p@v0.41.1/p2p/transport/webrtc/listener.go:199:40: unknown field LoggerFactory in struct literal of type webrtc.SettingEngine
/home/v1rtl/go/pkg/mod/github.com/libp2p/go-libp2p@v0.41.1/p2p/transport/webrtc/listener.go:200:16: settingEngine.SetAnsweringDTLSRole undefined (type webrtc.SettingEngine has no field or method SetAnsweringDTLSRole)
// ...
```
my guess is that it fails because webrtc transport is imported in multiple places (or maybe hust here) which breaks compilation:
```
/home/v1rtl/Coding/forks/go-libp2p/p2p/protocol/autonatv2/client.go:17: libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.