There is some setup that needs to be done to modernise the react-native runtime.
- Shimming globals
Some standard JS APIs aren't available in React Native, these need to be polyfilled, hopefully not forever.
See ./globals.js for the changes you need to make.
- Enable modern JS features
- libp2p uses ES2022 private properties in some places, so enable transpiling them for use with React Native. At the time of writing loose mode is also required.
$ npm i -D @babel/plugin-transform-private-methods
// babel.config.js
module.exports = {
//... other config
plugins: [
['@babel/plugin-transform-private-methods', { loose: true }]
]
}
- Add support for missing Node.js APIs
Some dependencies use Node.js APIs so these need to be added to the module resolver.
See ./babel-config.js for the changes you need to make.
Make sure you have completed the React Native - Environment Setup instructions till "Creating a new application" step, before proceeding.
Start Expo:
$ npm i
$ npm start
Follow the instructions - press i
to start iOS or a
for Android.
See the expo docs
$ npx expo run:android --device
For iOS you will need to provision a device certificate as normal.
$ npx expo run:ios --device
@libp2p/webrtc
can only run on a device since it needs native code
Put this at the top of your app file:
import debug from 'weald'
debug.enable('libp2p:*')