Migrating to v2.0
WebTorrent v2.0 is a major release with breaking changes. This guide will help you migrate your application.Breaking Changes
ESM Only
WebTorrent v2.0 is now ESM only. CommonJSrequire() is no longer supported.
Before (v1.x):
Deprecated getBuffer() Method
The file.getBuffer() method has been deprecated in favor of standard Web APIs.
Before (v1.x):
W3C-like File API
File objects now follow the W3C File API more closely:Storage Changes in Browser
WebTorrent v2.0 uses persistent storage (File System Access API + IndexedDB) in the browser instead of memory-only storage.This means torrents can persist across browser sessions, but you need more careful cleanup.
Render Media Deprecation
Thefile.renderTo() method has been removed. Use file.streamTo() instead.
Before (v1.x):
New Features in v2.0
Service Worker Support
v2.0 adds first-class Service Worker support for better streaming:Improved File Streaming
Better performance with the new streaming architecture:Built-in WebRTC Support
v2.3+ includes built-in WebRTC without needing separate packages.Migrating from v1.9 to v2.0
Step-by-Step Migration
Version 2.x.x Changes
v2.8.0 (2025-08)
- Feature: Updated
fs-chunk-storeto v5 for better performance - Feature: Peers stored as Map instead of Array for performance improvements
v2.7.0 (2025-08)
- Performance: Major performance improvements with peer management
- Fix: Connection count tracking
v2.6.0 (2025-04)
- Feature: Added option to store the bitfield in the file system
- Performance: Reduced memory usage for large torrents
v2.5.0 (2024-08)
- Breaking: Dropped IndexedDB chunk store in favor of File System Access API
- Performance: Significantly reduced memory usage in browser
v2.4.0 (2024-06)
- Feature: Added
seedOutgoingConnectionsoption to control outbound connections when seeding
v2.3.0 (2024-05)
- Feature: Built-in WebRTC support (no longer requires separate package)
- Performance: Faster peer connections
v2.2.0 (2024-03)
- Feature: Refactored file selections with non-overlapping data structure
- Performance: Improved piece selection algorithm
Common Migration Issues
Error: Cannot use import outside a module
Error: Cannot use import outside a module
Add Or rename files from
"type": "module" to your package.json:.js to .mjs.File.getBuffer is not a function
File.getBuffer is not a function
Replace with the new async methods:
Browser storage not persisting
Browser storage not persisting
Ensure you’re properly registering the service worker:Make sure
sw.min.js is served from your web server.ReferenceError: require is not defined
ReferenceError: require is not defined
You’re trying to use CommonJS in an ESM context. Convert to ESM:
Webpack Configuration
If you’re using Webpack, you may need to update your configuration for v2.0:Getting Help
If you encounter issues during migration:- Check the GitHub Issues
- Join the Gitter chat
- Visit
#webtorrenton IRC (freenode)
For production applications, thoroughly test your migration in a staging environment before deploying.