Hello, I’m trying to install moralis to my react native app and keep getting this error, Is there something I’m missing? I tried “npm i crypto” but that doesn’t work
Hey @clb
Install crypto-js package using:
npm install crypto-js
And then change the code on line 28 to this one.
var CryptoJS = require('crypto-js');
Let me know how it works
Now its saying… Unable to resolve module https, I dont think moralis is working with react native. I have zero vulnerabilities but after i install Moralis I get 10. Is there a work around without using API calls?
Heres what i get after ‘npm i https’:
While trying to resolve module https
from file /Users/u/app/node_modules/web3-providers-http/lib/index.js
, the package /Users/u/app/node_modules/https/package.json
was successfully found. However, this package itself specifies a main
module field that could not be resolved (/Users/u/app/node_modules/https/index.js
. Indeed, none of these files exist: …
Change it to:
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
sourceExts: ['jsx', 'js', 'ts', 'tsx'],
},
};
No errors but app wont start, doesnt go past the splash screen
Restarted metro now im getting this:
Error: Unable to resolve module http from /Users/u/app/node_modules/web3-providers-http/lib/index.js: http could not be found within the project or in these directories:
node_modules
…/node_modules
Install react-native-crypto
instead of crypto-js
And then change
var CryptoJS = require('react-native-crypto')
My bad, we needed to do this from the beginning.
npm uninstall crypto-js
npm i react-native-crypto --save
Still getting this error, I restarted everything
Error: Unable to resolve module http from /Users/u/app/node_modules/web3-providers-http/lib/index.js: http could not be found within the project or in these directories:
node_modules
…/node_modules
After npm i http:
Error: While trying to resolve module http
from file /Users/u/app/node_modules/web3-providers-http/lib/index.js
, the package /Users/u/app/node_modules/http/package.json
was successfully found. However, this package itself specifies a main
module field that could not be resolved (/Users/u/app/node_modules/http/index
. Indeed, none of these files exist:
Can you upload it to github and send me a link in DM?
Is this how to connect to moralis on react native:
const Moralis = require(‘moralis/react-native.js’)
Moralis.initialize(‘XXXXXXXXXXXX’);
Moralis.serverURL = ‘https://XXXXXXXXX.moralis.io:XXXX/server’;
You should install React Moralis:
npm install react-moralis --save
Take a look at React Moralis Docs
index.js
file:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { MoralisProvider } from 'react-moralis';
const theme = extendTheme({
config: {
initialColorMode: 'dark',
},
});
const appId = 'YOUR_APP_ID';
const serverUrl = 'YOUR_SERVER_URL';
ReactDOM.render(
<React.StrictMode>
<MoralisProvider appId={appId} serverUrl={serverUrl}>
<App />
</MoralisProvider>
</React.StrictMode>,
document.getElementById('root'),
);
For developing on React Native please use Moralis React SDK
The difference for developing on React Native is for metamask authentication and all that , you would need to do extra steps
I don’t need metamask i just want to access the data only
this is the index.js, exactly do I fix it for RN:
/**
- @format
*/
import {AppRegistry} from ‘react-native’;
import App from ‘./App’;
import {name as appName} from ‘./app.json’;
AppRegistry.registerComponent(appName, () => App);