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
Related
I'm making a mobile application with react native.
I want to use Realm (mongodb).
So after running:
npm install realm
realm was correctly added in the "node_modules" and I tried to import realm with:
import Realm from "realm";
If I do npm start and test the app, I get to following error message:
Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
I'm using windows and testing the app on an android device. Earlier questions about this matter on the internet suggested it is in my situation not needed to do "pod install".
I also tried to autolink realm, with:
react-native link realm
But then I get the warning:
warn Calling react-native link [packageName] is deprecated in favor of
autolinking. It will be removed in the next major release. Autolinking
documentation:
https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
(node:26016) Warning: Accessing non-existent property 'padLevels' of
module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created)
Does that mean that the autolinking is not successful, because autolinking will be removed in the next release?
Does any of you have suggestions on how I can successfully import Realm in my react native project?
Here are some of the dependency versions:
"expo": "^44.0.0",
"realm": "^10.14.0"
"react-native": "0.64.3",
Add this package:
npm install realm#hermes
Works for me.
run this command:
expo run:android
you must build your project first
and remember realm is working only on production environment
As the error message suggests, you need to install the pod files for realm to work with iOS. Those are the steps:
In your project folder run npm install realm. It adds the npm package to your react native project
In your iOS folder (cd ios) run pod install. It gets all iOS realm libraries and compiles the iOS-part of your npm package and creates the .xcworkspace.
Add the import to your component: import Realm from "realm";
Switch back to your project folder and run your project: react-native run-ios
Hope that solves your problem!
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
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
I am using https://reactnative.dev/docs/environment-setup 0.64
I npm install #walletconnect/client
put below import in App.js
import WalletConnect from "#walletconnect/client";
after npx react-native run-ios and got below error:
error: Error: While trying to resolve module `crypto` from file `/Users/hahaha/workspace/mobile/reactnative/nonft/node_modules/#pedrouid/iso-crypto/dist/cjs/helpers/env/node.js`, the package `/Users/hahaha/workspace/mobile/reactnative/nonft/node_modules/crypto/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/hahaha/workspace/mobile/reactnative/nonft/node_modules/crypto/index.js`. Indeed, none of these files exist:
I tried to remove node_modules folder and npm install again but still get the same error.
I am sure that it is thrown by #walletconnect/client because when I removed
import WalletConnect from "#walletconnect/client";
then the error gone
crypto is a built in Node module, which isn't available in React Native, as iOS/Android apps don't run with a Node runtime - only web apps do.
There are a few ways to solve this problem, all of them fairly hacky.
One way is to replace the crypto module with a React Native native module that does the same thing. React-native-crypto is the package used by create-react-native-dapp (https://www.npmjs.com/package/create-react-native-dapp) to integrate with WalletConnect: https://www.npmjs.com/package/react-native-crypto
To get this integration working, note that you'll need to be able to link modules and run rn-nodeify, as it mentions in the instructions on that npm package:
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
If you're using Expo, note that you'll need to eject Expo before this can work.
Another hacky workaround is to run WalletConnect in a WebView using react-native-webview. There's an old but working example of this that you can just use to plug and play WalletConnect without requiring linking that you can get here: https://github.com/cawfree/react-native-walletconnect
Note that that repo is archived and effectively hardcoded to WalletConnect version 1.0.0, but it's a pretty simple codebase - you can just effectively copy and paste its code and update it to the latest version of WalletConnect to get it working with a later version if desired.
As a final note, there are multiple ways to get node modules running in React Native on top of rn-nodeify. If you'd like to explore other methods of getting node modules running, here's a quick rundown of other possibilities: https://gist.github.com/parshap/e3063d9bf6058041b34b26b7166fd6bd
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'