Add babel polyfill to React Native Project - react-native

I´m having a issue on android. Got this error:
undefined is not a function(evaluating '_iterator2typeof
Symbol==='function'?Symbol.iterator:'##iterator'´)
I think it is related to the use of for of, es6.
Can i add babel-polyfill to React Native Project ?

In order to add babel-polyfill to your react-native project after installing
npm install --save babel-polyfill
just import it like this in your entry endpoint:
import 'babel-polyfill';
Now you can use new built-ins like Promise or WeakMap, static methods like Array.from and instance methods like Array.prototype.includes, etc.

You can use
npm install es6-symbol --save
Then add in your index.android.js & index.ios.js
import 'es6-symbol/implement'

Related

Magic.link React Native cannot import WebView from react-native

working on implementing magic.link using react-native but i get an error when importing Magic
import { Magic } from "#magic-sdk/react-native";
error:
Attempted import error: 'WebView' is not exported from 'react-native'.
I think its because of the sub dependency of react-native-webview has been removed, but i did install it. npm install --save react-native-webview#^8.0.0 as the tutorial says? Stuck for a while now, not sure how to procede with Magic
https://magic.link/docs/login-methods/email/integration/react-native
This link was attached to the docs https://github.com/react-native-webview/react-native-webview/issues/373 . But don't know why it should not work, since the correct react-native-webview dependency was installed (8.0.0) or (^8.0.0, which is 8.2.1)
I installed the packages as the tutorial suggests
yarn add #magic-sdk/react-native
# Ensure the required `peerDependencies` are installed
yarn add react-native-webview#^8.0.0
Use this one:
npm install --save #magic-sdk/react-native
then try to link it using npm react-native link

How to use antmedia npm package

I did not find any relevant documentation regarding how to use the npm package of antmedia.
I install it by doing a yarn add #ant-media/webrtc_adaptor.
When i try to import it
import { WebRTCAdaptor } from '#antmedia/webrtc_adaptor';
Which results in this error
I realized that in package.json, it is the index.html that is in main
Is there a documentation about it ? I am currently not using React Native
Note: yarn add #ant-media/webrtc_adaptor#1.2.0 is definitly not working

How to use react-native submodule properly?

I am trying to move some shared functions to git submodule and I am facing an issue that I can't overcome.
I have a simple react-native CLI project and git submodule inside with npm package uuid.
I've created the function:
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
export const generateId = (): string => uuidv4();
But when I try to import the function from the submodule, I am receiving the error: "Native Module not found".
It seems that the submodule doesn't have a react-native environment, but when I install react-native in the submodule I receive another error: Invariant Violation: Module RCTDeviceEventEmitter is not a registered callable module (calling emit)
Seems like a very easy task and there should be some best practices how to create such a submodule.
Thanks in advance.
My guess is that having react-native-get-random-values as a dependency in your submodule is requiring some react-native API calls, try moving that import to your main react-native app code (index.js) and use only javascript dependencies in your submodule. If you really need to add other dependencies that use react-native in the submodule, I think you would need to recreate it as a react-native library https://reactnative.dev/docs/native-modules-setup

Unable to resolve module crypto in reactnative

I have posted this here have created react-native app using
react-native init myapp
added web3 in package.json
npm install
react-native run-ios
but i am getting the error unable to resolve module crypto from web3-eth-accounts. Is there any way to fix this
unable to resolve crypto
Crypto is a node js module, when React Native is run - it uses Javascript Core. Crypto isn't include within this. When I installed crypto I used the following package:
https://www.npmjs.com/package/react-native-crypto
Instructions:
npm i --save react-native-crypto
# install peer deps
npm i --save react-native-randombytes
react-native link react-native-randombytes
# install latest rn-nodeify
npm i --save-dev tradle/rn-nodeify
# install node core shims and recursively hack package.json files
# in ./node_modules to add/update the "browser"/"react-native" field with relevant mappings
./node_modules/.bin/rn-nodeify --hack --install
rn-nodeify will create a shim.js in the project root directory
// index.ios.js or index.android.js
// make sure you use `import` and not require!
import './shim.js'
// ...the rest of your code
Import shim.js in your index.js file.
When you have done that crypto should be made available, if it still doesn't work I had to create a const in my App.js file like so:
export const cryp = require('crypto');
And import it into the components you need.
UPDATE
I've done a fresh build for this, I followed the below:
react-native init TestApp
Follow the instructions above for Crypto.
Linked:
react-native link
react-native run-ios
react-native-crypto don't work on recent react-native version 0.63.3 and react version 16.13.1, any more.
I used crypto-js package. The version is 3.1.9-1 in my react-native app. It's working well.
You can add below line in package.json file.
"crypto-js": "3.1.9-1",
crypto is a node's library that works with the browser however we can use it with react native with some hacks mentioned below follow these steps and boom! you are ready to rock.
npm i --save react-native-crypto
==> install peer deps
npm i --save react-native-randombytes
react-native link react-native-randombytes
==>install latest rn-nodeify
npm i --save-dev tradle/rn-nodeify
==> install node core shims and recursively hack package.json files
==> in ./node_modules to add/update the "browser"/"react-native" fieldwith relevant mappings
./node_modules/.bin/rn-nodeify --hack --install
i had the same problem, it seems the crypto module is not supported by react native because when i install crytpo , it does not have an index.js file in the node_modules. so my problem came about when i was trying to use jsonwebtoken which uses crypto to encrypt data. so i uninstalled jsonwebtoken and switched to react-native-pure-jwt

react-native-in-app-utils not added to NativeModules

I ran:
react-native install react-native-in-app-utils
and it completed successfully. I added the import to my code:
import { NativeModules } from 'react-native'
const { InAppUtils } = NativeModules
No errors occur in building and starting but NativeModules is empty and InAppUtils is undefined.
I have used this successfully in RN 0.48; this is on RN 0.55.
Is there some step I am missing?
Documentation details for react-native-in-app-utils is misleading regarding Linking.
Install Library (react-native-in-app-utils) using rnpm. you need to install rnpm.
1.npm install rnpm -g
2. rnpm install react-native-in-app-utils
rnpm will auto link your library for IOS.
SUGGESTION
Do not install library using Yarn , npm and react-native install react-native-in-app-utils
react-native-in-app-utils requires you to have created your app with 'react-native init`. Or, you have to eject from CRNA.
CRNA can't use native modules unless you eject/detach (similar to expo, as they're interrelated):
https://github.com/chirag04/react-native-in-app-utils/issues/130
https://facebook.github.io/react-native/docs/getting-started.html