Does React has a solution for this issue. This is really frustrating
none of thee fix workaround work.
this is my package.json
{
"name": "HotelReservation",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "^16.3.0-alpha.1",
"react-native": "0.54.0",
"react-navigation": "^1.5.1"
},
"devDependencies": {
"#babel/core": "^7.6.0",
"#babel/runtime": "^7.6.0",
"#react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.4.0",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"
}
}
and class App
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import HomeScreen from './screens/HomeScreen'
import ProfileScreen from './screens/ProfileScreen'
const MainNavigator = createStackNavigator({
Home: {screen: HomeScreen},
Profile: {screen: ProfileScreen},
});
const App = createAppContainer(MainNavigator);
export default App;
Anything I should update ?
Is that a react issue or a bug with react-navigation
Looking at your package.json file, it seems like you do not have the following libraries: react-native-reanimated, react-native-gesture-handler and react-native-screens. If you are using bare React Native project, you need to add these libraries and link those libraries. For versions of React Native 0.60 and higher, these libraries will be automatically linked after you add the above libaries (i.e either use yarn or npm to add those). However, as you are using React Native 0.59, you need to link the dependencies manually. Refer to this documentation to add and link those dependencies. It also gives you all the details of getting started on React Navigation.
Related
I'm a react-native beginner.
I was doing stack screen. Then I've got the below error.
Error: Unable to resolve module react-navigation-stack from /Users/chosohee/app2/src/navigation/index.js: react-navigation-stack could not be found within the project or in these directories:
node_modules
../node_modules
1 | import { createAppContainer, createSwitchNavigator } from 'react-navigation';
> 2 | import { createStackNavigator } from 'react-navigation-stack';
| ^
3 | import LoginScreen from './LoginScreen';
4 | import HomeScreen from './HomeScreen';
5 |
at ModuleResolver.resolveDependency (/Users/chosohee/app2/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:178:15)
at DependencyGraph.resolveDependency (/Users/chosohee/app2/node_modules/metro/src/node-haste/DependencyGraph.js:264:43)
at Object.resolve (/Users/chosohee/app2/node_modules/metro/src/lib/transformHelpers.js:170:21)
at resolveDependencies (/Users/chosohee/app2/node_modules/metro/src/DeltaBundler/graphOperations.js:466:33)
at processModule (/Users/chosohee/app2/node_modules/metro/src/DeltaBundler/graphOperations.js:232:31)
at async addDependency (/Users/chosohee/app2/node_modules/metro/src/DeltaBundler/graphOperations.js:361:18)
at async Promise.all (index 7)
at async processModule (/Users/chosohee/app2/node_modules/metro/src/DeltaBundler/graphOperations.js:279:3)
at async addDependency (/Users/chosohee/app2/node_modules/metro/src/DeltaBundler/graphOperations.js:361:18)
at async Promise.all (index 7)
Here is my src/navigation/index.js
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import LoginScreen from './LoginScreen';
import HomeScreen from './HomeScreen';
const AuthStack = createStackNavigator(
{
LoginScreen: {screen: LoginScreen},
HomesScreen: {screen: HomeScreen}
},
{
initialRouteName: 'LoginScreen'
}
);
const AppNavigator = createSwitchNavigator(
{
Auth: AuthStack
},
{
initialRouteName: 'Auth',
}
);
export default createAppContainer(AppNavigator);
Here is my package.json
{
"name": "app2",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/masked-view": "0.1.11",
"#react-navigation/bottom-tabs": "6.5.2",
"#react-navigation/native": "6.1.1",
"#react-navigation/native-stack": "6.9.7",
"#react-navigation/stack": "6.3.10",
"react": "18.1.0",
"react-native": "0.70.6",
"react-native-gesture-handler": "2.8.0",
"react-native-reanimated": "2.13.0",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "3.18.2"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#babel/runtime": "^7.12.5",
"#react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.32.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "0.72.3",
"react-test-renderer": "18.1.0"
},
"jest": {
"preset": "react-native"
}
}
I tried
Unable to resolve module 'react-navigation'
https://github.com/react-navigation/react-navigation/issues/9976
https://reactnavigation.org/docs/troubleshooting/
when I tried
npx react-native start --reset-cache
I got another error below.
error listen EADDRINUSE: address already in use :::8081.
Error: listen EADDRINUSE: address already in use :::8081
at Server.setupListenHandle [as _listen2] (node:net:1717:16)
at listenInCluster (node:net:1765:12)
at Server.listen (node:net:1853:7)
at /Users/chosohee/app2/node_modules/metro/src/index.flow.js:398:14
at new Promise (<anonymous>)
at earlyPortCheck (/Users/chosohee/app2/node_modules/metro/src/index.flow.js:394:11)
at exports.runServer (/Users/chosohee/app2/node_modules/metro/src/index.flow.js:155:9)
at Object.runServer [as func] (/Users/chosohee/app2/node_modules/#react-native-community/cli-plugin-metro/build/commands/start/runServer.js:123:49)
at async Command.handleAction (/Users/chosohee/app2/node_modules/#react-native-community/cli/build/index.js:142:9)
info Run CLI with --verbose flag for more details.
Your import is not correct according to the stack navigation documentation you need to import createStackNavigator from #react-navigation/stack not from react-navigation-stack like this:
import { createStackNavigator } from '#react-navigation/stack';
For more information you can check the documentation from here.
i am writing react native custom package.
that package uses react-native-webview internally.
i want to test my custom package locally, but before that I need to mention dependencies for 'react-native-webview'.
for custom package: i have mentioned dependencies like below, but i am getting error:
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"devDependencies": {
"#babel/core": "^7.19.3",
"#babel/preset-env": "^7.19.3",
"#babel/runtime": "^7.19.0",
"react": "^18.1.0",
"react-native": "^0.70.1"
},
"dependencies": {
"react-native-webview": "^11.23.1"
}
and here are depedencies for test app, which tests custom package 'rn-timer' locally:
"devDependencies": {
"#babel/core": "^7.19.3",
"#babel/preset-env": "^7.1.6",
"#babel/runtime": "^7.19.0",
"#react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.32.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.72.1",
"react-test-renderer": "18.1.0"
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"react": "^18.2.0",
"react-native": "^0.70.1",
"rn-timer": "file:../rn-timer"
}
i am getting following error:
ERROR TypeError: Cannot read property 'isFileUploadSupported' of null, js engine: hermes
at App (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.demoapp2&modulesOnly=false&runModule=true:112639:89)
at RCTView
at View
at RCTView
at View
at AppContainer (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.demoapp2&modulesOnly=false&runModule=true:102788:36)
at demoapp2(RootComponent) (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.demoapp2&modulesOnly=false&runModule=true:108308:28)
ERROR Error: Requiring module "../rn-timer/index.js", which threw an exception: TypeError: Cannot read property 'isFileUploadSupported' of null, js engine: hermes
at App (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.demoapp2&modulesOnly=false&runModule=true:112639:89)
at RCTView
at View
at RCTView
at View
at AppContainer (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.demoapp2&modulesOnly=false&runModule=true:102788:36)
at demoapp2(RootComponent) (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.demoapp2&modulesOnly=false&runModule=true:108308:28)
ERROR TypeError: Cannot read property 'CountdownTimer' of undefined
This error is located at:
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in demoapp2(RootComponent), js engine: hermes
ERROR TypeError: Cannot read property 'CountdownTimer' of undefined
This error is located at:
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in demoapp2(RootComponent), js engine: hermes
WARN Tried to call timer with ID 8 but no such timer exists.
please guide me how can i mention depedencies for "react-native-webbview" correctly.
package code:
Countdowntimer.js
import React from "react";
import { Button, StyleSheet, View } from "react-native";
import WebView from "react-native-webview";
function CountdownTimer(props) {
return <WebView source={{ uri: "https://reactnative.dev/" }} />;
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "red",
},
});
export default CountdownTimer;
index.js
export { default as CountdownTimer } from "./CountdownTimer";
test app code:
App.js
import React from 'react';
import {View, StyleSheet} from 'react-native';
import {CountdownTimer} from 'rn-timer';
function App(props) {
return (
<View style={styles.container}>
<CountdownTimer />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'orange',
},
});
export default App;
Update:
i have updated package.json:
for library: i have added react-native-webview in the peer dependencies of the custom package.
for demo/test app: i have added react-native-webview in the dependencies of test project.
Now i am getting following errors:
Now , package.json for demo app looks like:
{
"name": "demoapp2",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"devDependencies": {
"#babel/core": "^7.19.3",
"#babel/preset-env": "^7.1.6",
"#babel/runtime": "^7.19.0",
"#react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.32.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.72.1",
"react-test-renderer": "18.1.0"
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"react": "^18.2.0",
"react-native": "^0.70.1",
"react-native-webview": "^11.23.1",
"rn-timer": "file:../rn-timer"
}
}
and package.json for library looks like:
{
"name": "rn-timer",
"version": "1.0.0",
"description": "this is my timer component",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"timer",
"countdown"
],
"author": "shivang",
"license": "MIT",
"peerDependencies": {
"react": "^18.2.0",
"react-native": "^0.70.1",
"react-native-webview": "^11.23.1"
},
"devDependencies": {
"#babel/core": "^7.19.3",
"#babel/preset-env": "^7.19.3",
"#babel/runtime": "^7.19.0",
"react": "^18.2.0",
"react-native": "^0.70.1"
}
}
Update 2:
This is crazy,
if i add react, react-native, react-native-webview as a dependency in demo app and as a peer dependency in library code. its throwing error like:
no module found in library code.
and to fix above error, if i add react, react-native, react-native-webview as a devdependency in library code its throwing error like:
Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
i am out of idea, what to do...
First of all, you should use create-react-native-library to make the custom react-native package
npx create-react-native-library#latest react-native-awesome-library
Note: This package uses babel-plugin-module-resolver instead of making symlink or copying files. It will also make Example folder where you can test your custom package
second, add react-native-webview in the peer dependencies of the custom package and add react-native-webview in the dependencies of test project
I am very new to React native I am trying to show content it is showing from starting. But I have
To show the content from the container, but I don't know how to apply this in React native. So
So someone please help me how to use container in React native.
In this component I tried some code please check it once
This is App.js
import React from 'react';
import {View, Text} from 'react-native';
const App = props => {
return (
<View>
<Text>Hi Mark</Text>
</View>
);
};
export default App;
These are the packages I installed in my React native project
{
"name": "testone",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/masked-view": "^0.1.10",
"#react-navigation/native": "^5.3.2",
"#react-navigation/stack": "^5.3.6",
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.8.0",
"react-native-safe-area-context": "^1.0.0",
"react-native-screens": "^2.7.0"
},
"devDependencies": {
"#babel/core": "7.9.6",
"#babel/runtime": "7.9.6",
"#react-native-community/eslint-config": "0.0.5",
"babel-jest": "24.9.0",
"eslint": "6.8.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.58.0",
"react-test-renderer": "16.11.0"
},
"jest": {
"preset": "react-native"
}
}
Note I am not using expo I am using pure React native for app development.
Add margin style property to root View to make it like container
import React from "react";
import { Text, View } from "react-native";
const App = () => {
return (
<View style={{ margin:100 }}>
<Text>Hi There!</Text>
</View>
);
};
export default App;
I have a problem when I try to add a bottomnavigation in my app on the main screen:
This is the main screen code:
// Main.js
import React from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
import firebase from 'react-native-firebase';
import { NavigationContainer } from '#react-navigation/native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
export default class Main extends React.Component {
state = { currentUser: null }
componentDidMount() {
const { currentUser } = firebase.auth()
this.setState({ currentUser })
}
render() {
const { currentUser } = this.state
return (
<View style={styles.container}>
<Text>
Hi {currentUser && currentUser.email}!
</Text>
</View>
)
}
}
const bottomTabNavigator = createBottomTabNavigator(
{
Main: Main,
},
{
initialRouteName: 'Main'
}
);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}
})
No when I run it I get this error:
Error: Creating a navigator doesn't take an argument. Maybe you are trying to use React Navigation 4 API with React Navigation 5? See https://reactnavigation.org/docs/en/hello-react-navigation.html for usage guide.
<unknown>
index.bundle?platform=ios&dev=true&minify=false:109707:24
<global>
Main.js:24
loadModuleImplementation
require.js:322:6
guardedLoadModule
require.js:201:45
runUpdatedModule
require.js:657:17
metroHotUpdateModule
require.js:533:8
define
require.js:53:24
global code
Main.bundle?platform=ios&dev=true&minify=false&modulesOnly=true&runModule=false&shallow=true:1:4
<unknown>
[native code]:0
inject
injectUpdate.js:62:35
forEach
[native code]:0
injectUpdate
injectUpdate.js:71:26
on$argument_1
HMRClient.js:40:21
emit
index.js:202:37
_ws.onmessage
WebSocketHMRClient.js:72:20
EventTarget.prototype.dispatchEvent
event-target-shim.js:818:39
_eventEmitter.addListener$argument_1
WebSocket.js:232:27
emit
EventEmitter.js:190:12
callFunctionReturnFlushedQueue
[native code]:0
So i checked my package file which is:
{
"name": "kowop",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/masked-view": "^0.1.6",
"#react-navigation/bottom-tabs": "^5.0.3",
"#react-navigation/material-bottom-tabs": "^5.0.1",
"#react-navigation/native": "^5.0.1",
"email-validator": "^2.0.4",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-firebase": "^5.6.0",
"react-native-gesture-handler": "^1.5.6",
"react-native-paper": "^3.6.0",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "^0.6.4",
"react-native-screens": "^2.0.0-beta.2",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^4.1.1",
"react-navigation-stack": "^2.0.16",
"typescript": "^3.7.5"
},
"devDependencies": {
"#babel/core": "7.8.3",
"#babel/runtime": "7.8.3",
"#react-native-community/eslint-config": "0.0.5",
"babel-jest": "24.9.0",
"eslint": "^6.8.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.56.4",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
But apparently react-navigation can't be updated above 4.11 or at least that is what the npm page says.
244,663
Version
4.1.1
License
MIT
Unpacked Size
41 kB
Total Files
12
Issues
133
Pull Requests
3
So I am a bit lost here. Does anyone see what I do wrong?
Thanks a lot!
Tim
You are using react-navigation v5 dependencies but in your code you implement with v4 api way.
You should change react-navigation dependencies to v4 to make your code work.
I made you code work on snack : demo
bundling failed: Error: Unable to resolve module react-navigation-stack from App.js: react-navigation-stack could not be found within the project.
i tried removing the node modules and reinstalling them, clearing the cache, trying the same in a new fresh project but no result
Package.json file
{
"name": "navigator",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "16.9.0",
"react-native": "0.61.2",
"react-native-gesture-handler": "^1.4.1",
"react-native-reanimated": "^1.3.0",
"react-native-screens": "1.0.0-alpha.23",
"react-navigation": "^4.0.10"
},
"devDependencies": {
"#babel/core": "^7.6.2",
"#babel/runtime": "^7.6.2",
"#react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
App.js
import React from 'react';
import { View, Text } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import HomeScreen from './src/screens/HomeScreen';
import ComponentScreen from './src/screens/ComponentScreen';
const navigator = createStackNavigator(
{
Home: HomeScreen
},
{
initialRouteName: 'Home',
defaultNavigationOptions: {
title: 'App'
}
}
);
export default createAppContainer(navigator);
Your package.json does not have the module you want to use. You need to install a module.
yarn add react-navigation-stack
or
npm install react-navigation-stack
npm install react-navigation-stack
npm install react-navigation-stack --save