How do I fix RN suddenly being unable to find local modules (Unable to resolve module)? - react-native

I've got a strange situation where suddenly my RN app won't load any of its scenes. The app has been running fine for weeks and I haven't moved any of the files. The failure:
error: bundling: UnableToResolveError: Unable to resolve module `./src/scenes/splash` from `/Users/jcollum/projects/starsApp/index.ios.js`: Directory /Users/jcollum/projects/starsApp/src/scenes/splash doesn't exist
at Promise.resolve.then (/Users/jcollum/projects/starsApp/node_modules/react-native/packager/src/node-haste/DependencyGraph/ResolutionRequest.js:445:15)
at process._tickCallback (internal/process/next_tick.js:109:7)
My import statements look like:
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
import { Router, Scene } from 'react-native-router-flux';
import Icon from 'react-native-vector-icons/FontAwesome';
import Splash from './src/scenes/splash';
The scene definitely exists:
$ ll /Users/jcollum/projects/starsApp/src/scenes/splash.js
-rw-r--r-- 1 jcollum staff 722B Apr 26 10:12 /Users/jcollum/projects/starsApp/src/scenes/splash.js
And it has an export default:
import React, { Component, PropTypes } from 'react';
import { View, Text, TouchableHighlight, Image } from 'react-native';
import styles from '../styles'
import { Actions } from 'react-native-router-flux';
export default class Splash extends Component {
componentWillMount() {
setTimeout(() => {
Actions.Home()
}, 1000);
}
render() {
console.log(`rendering Splash`);
return (
<View ...
Things I have tried:
restarting packager
resetting content and settings
checking out a previous commit
clearing temp dir: rm -fr $TMPDIR/react-*
react-native --version
react-native-cli: 2.0.1
react-native: 0.43.2
What could be causing this? Why would this suddenly stop loading resources? What's the next thing to try?

Solution (don't know why this works, sorry):
Stop any running packager
Add this to package.json: "clean-start": "rm -rf node_modules && yarn install && rm -rf $TMPDIR/react* && npm start --reset-cache", (or npm install if you don't use yarn)
npm run clean-start

I faced the similar issue once and what i did was nothing fancy, I just cut all the files which were giving error and copied at some place(outside my project dir) and then paste those files again at their place helped me..
Cheers :)

In my case, ran
npm cache verify
in console at my project directory, all was well. Hope it helps

Related

React Native Module not found: Can't resolve '#react-navigation/core' with react-native-router-flux

I have this basic React Native Code which fails to compile as soon as I import anything from react-native-router-flux. It throws Module not found: Can't resolve '#react-navigation/core'
If I uncomment line import { Router, Scene } from "react-native-router-flux";, everything works fine. I also manually did npm install #react-navigation/core but to no avail
import React from "react";
import { Router, Scene } from "react-native-router-flux";
class Index extends React.Component {
render() {
return <div></div>
}
}
export default Index;
What could I be missing?
Versions
React v17.0.2
react-native-router-flux v4.3.1
React-native v0.66.3
The latest react-native version (v0.66.3) is incompatible with react-native-router-flux (v4.3.1) which is pretty old. Its better to look for #react-navigation/native
Thanks #XplosiVe06 for pointing out

`unable to resolve module #react-native-community/async-storage` broke down my React Native environment

I'm basically having the issue same as here.
https://github.com/firebase/firebase-js-sdk/issues/1899
How I got this error
Since AsyncStorage is deprecated, I tried to install #react-native-community/async-storage following the official documentation
But it failed completely as I got the error above.
Thus I wanted to roll back to my previous working version except none of what I did worked.
None of these solved my problem
4 commands suggested on the error screen
undoing yarn add with yarn remove
I also did npm install #react-native-community/async-storage, did not work.
3.5 so I did npm uninstall #react-native-community/async-storage It was removed, but roll-back did not work.
Re-installing the react-native-cli
Re-creating a completely new project from scratch, but it is still giving the same error.
I could not find a solution for this. Please help.
If it's on iOS you probably forgot to do pod install.
Paste this inside ios/Podfile:
pod 'RNCAsyncStorage', :path => '../node_modules/#react-native-community/async-storage'
then just do cd ios && pod install
EDIT.
I createad a project from scratch, this are the steps i did to make asyncStorage run on iOS and Android:
1) react-native init AsyncTest
2) npm i #react-native-community/async-storage
(trying to use asyncStorage during this step shows error, but works on Android)
3) Pasted inside Podfile this pod:
pod 'RNCAsyncStorage', :path => '../node_modules/#react-native-community/async-storage'
4) From terminal, assuming you are in the project folder do cd ios and pod install
5) Project run succesfully on iOS and works.
react-native version was 0.60.4
This is how the project test App.js was for the test:
import React from 'react';
import { View } from 'react-native';
import AsyncStorageTest from './AsyncStorageTest'
const App = () => {
return (
<View>
<AsyncStorageTest />
</View>
);
};
export default App
And AsyncStorageTest is:
import React, { Component } from 'react'
import { View, Text, Button } from 'react-native'
import AsyncStorage from '#react-native-community/async-storage';
export class AsyncStorageTest extends Component {
constructor(props) {
super(props)
this.state = {
storedData: "myValue"
}
}
storeData = async () => {
console.log("inside storeData")
try {
await AsyncStorage.setItem('Test', 'TestValue')
} catch (e) {
console.log(e)
}
}
getData = async () => {
console.log("inside getData")
try {
const value = await AsyncStorage.getItem('Test')
this.setState({ storedData: value })
} catch (e) {
// error reading value
}
}
render() {
return (
<View style={{ marginTop: 40 }}>
<Text> {this.state.storedData}</Text>
<Button title={"storeData"} onPress={this.storeData}></Button>
<Button title={"getData"} onPress={this.getData}></Button>
</View>
)
}
}
export default AsyncStorageTest
Tested and worked, see if you missed something.
Make sure the that #react-native-community/async-storage is unlinked from your project.
Somehow the path to the package got changed.
This helped me:
import AsyncStorage from '#react-native-async-storage/async-storage';
For someone like me please double-check this as well:
When you install npm i #react-native-community/async-storage you should import it as import AsyncStorage from '#react-native-community/async-storage'; and DO NOT import is as import AsyncStorage from '#react-native-async-storage/async-storage';
after i run npm install react-native-dotenv
i take this error,
then i rerun npm install;
cd ios;pod install;cd ..;
and then close the terminal and uninstall app from phone,and restart them,it's works.
my version "react": "16.9.0",
"react-native": "0.61.5",
I solved this issue by installing #react-native-community/async-storage aliased to #react-native-async-storage/async-storage
The command was
yarn add #react-native-async-storage/async-storage#npm:#react-native-community/async-storage
or
npm install --save #react-native-async-storage/async-storage#npm:#react-native-community/async-storage
I solved this issue following the import...
import {AsyncStorage} from 'react-native';
When you install npm install #react-native-community/async-storage
You could import => import AsyncStorage from '#react-native-community/async-storage';
Dont import this => import AsyncStorage from '#react-native-async-storage/async-storage';

Unable to resolve module 'react-redux'...module 'react-redux' does not exist in haste module map

The code in app.js file with import statements for react redux is created to display a header with a text called "Tech stack".
App.js
import React from 'react';
import { View } from 'react-native';
import { Header } from './components/common';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from './reducers';
const App = () => {
return(
<Provider store={createStore(reducers)}>
<View>
<Header headerText="Tech Stack" />
</View>
</Provider>
);
};
export default App;
This is the index file
index.js
import { AppRegistry } from 'react-native';
import App from './src/App';
AppRegistry.registerComponent(tech_stack, () => App);
While running this on the terminal, it throws a error saying unable to resolve module 'react-redux'.
Close the JS bundle(a terminal starts when you run app for first time) and rerun it using the command react-native start from the project path. Basically, you need to rerun the JS bundle after every package installation.
Install 'react-redux' by using
npm install --save react-redux
if you not installed it. By seeing your comment as you mentioned that you installed redux only.
Then restart the JS bundle by using
react-native start --reset-cache
I've faced this issue just now. actually, Our (you and I) main issue is naming the global state folder name is redux and the bundler falls in a conflict because there is a folder inside node_modules that name is redux too.
In fact, the main issue is this line:
import { createStore } from 'redux';
I renamed the resux stuffs folder to reduxStore instead of redux and then everything works properly.
This error occurs because you do not have Redux-Thunk middleware installed on your application. To install run:
npm install redux-thunk
Then, restart your application:
react-native start
More information: https://github.com/reduxjs/redux-thunk
I just ran into this problem and solved it by installing redux in addition to react-redux. Apparently, react-redux requires it.

Including paypal-rest-sdk in react-native project produces an error

When I import Paypal-Rest-SDK and try running:
react-native run-android
An error occurs:
"undefined is not a function(evaluating 'r(d[9]).configure')"
Before this error occurred, I deleted the node_modules folder and reinstalled all modules again, because I had a similar error with "evaluating process.versions.openssl". when I call node -p process.versions, the following is printed:
{ http_parser: '2.8.0',
node: '8.12.0',
v8: '6.2.414.66',
uv: '1.19.2',
zlib: '1.2.11',
ares: '1.10.1-DEV',
modules: '57',
nghttp2: '1.32.0',
napi: '3',
openssl: '1.0.2p',
icu: '60.1',
unicode: '10.0',
cldr: '32.0',
tz: '2017c' }
and my Code is the following for using the paypal-sdk:
'use strict';
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, TouchableHighlight, Linking} from 'react-native';
var paypal = require('paypal-rest-sdk');
paypal.configure({
mode: 'sandbox', // Sandbox or live
client_id: 'x',
client_secret: 'y'});
export default class Paypal extends Component{
constructor(props)
{
super(props);
console.log(process);
}
render()
{
return(
<View>
<Text>This is gonna be a PayPal Thing</Text>
</View>
);
}
}
I hope someone can help me. I've googled almost the entire day for this issue.
UPDATE :
The Problem is not the include of the paypal-rest-sdk, but the next line when I try to configure the paypal variable. The error dissapears when I comment them out ...but as far as I know it is necessary to configure that
Update No.2
After running
npm install --save paypal-rest-sdk
I'm back at the problem
undefined is not an object (evaluating 'process.versions.openssl')
You are using paypal-rest-sdk which is NodeJS PayPal SDK, I belive it is not compatible with React Native. I suggest to try something React Native specific like
https://www.npmjs.com/package/react-native-paypal-wrapper
https://www.npmjs.com/package/react-native-paypal
Or use plain PayPal rest API https://developer.paypal.com/docs/api/overview/#api-requests

Adding NPM module in React Native Throws Error (unable to resolve module url)

To be specific I'm using meta-extractor module in react native.
'use strict';
//import React Native
import React, { Component } from 'react';
import {
Text,
StyleSheet,
View,
TextInput,
TouchableHighlight,
} from 'react-native';
var styles = require('../styles/styles');
var metagetplus = require('../../node_modules/meta-extractor');
Here is the error message:
Unable to resolve module url from /Users/name/Desktop/instaldr/node_modules/meta-extractor/index.js: Unable to find this module in its module map or any of the node_modules directories under /Users/node_modules/url and its parent directories
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: watchman watch-del-all.
2. Delete the node_modules folder: rm -rf node_modules && npm install.
3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache.
I tried all suggested resolution methods mentioned in that link, but nothing seems to solve the issue. Can anyone help me out here?
Importing components changed, should not use require anymore, try:
import metagetplus from ('meta-extractor')
1 . Have you seen the package.json ... if the package "meta-extractor" is not listed in package.json it might break the whole system ?
2 . Try to use the commonjs require method :
const metagetplus = require('meta-extractor');
Sometimes modules only work with commonjs require method ... it might not work with import statements all the time . the package "meta-extractor" hasn't been updated for quite a while so it might not jut work with import statements ...
So what you can do is this ...
1 . Clear watchman : watchman watch-del-all
2 . Clear node_modules : rm -rf node_modules && npm install
3 . Install the package : npm i meta-extractor
4 . Edit code file :
'use strict';
import React, { Component } from 'react';
import {
Text,
StyleSheet,
View,
TextInput,
TouchableHighlight,
} from 'react-native';
const styles = require('../styles/styles');
const metagetplus = require('meta-extractor');
Hope it works ...