React Native error: "Failed to compile Syntax Error None of these files exist: " - react-native

I'm taking a React Native tutorial and I'm getting the error:
Failed to compile
Syntax Error
None of these files exist:
*..\..\..\..\..\.src\screens\ListScreen(.native|ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|tsx|ios.js|native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|native.json|.json)
*..\..\..\..\..\.src\screens\ListScreen\index(.native|ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|tsx|ios.js|native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|native.json|.json)
There are only three files being imported into my App.js file and the error shows when I import ListScreen from ".src/screens/ListScreen". When I comment out that line the error goes away. I have no idea what's causing it.
Below is the code from the four JS files and the folder structure. It's a course on Udemy and no one else has encountered it so I'm not sure what I'm doing wrong since all the other files were authored by the instructor which I downloaded at the beginning of the course.
App.js
import { createAppContainer } from "react-navigation";
import { createStackNavigator } from "react-navigation-stack";
import HomeScreen from "./src/screens/HomeScreen";
import ComponentsScreen from "./src/screens/ComponentsScreen";
import ListScreen from ".src/screens/ListScreen";
const navigator = createStackNavigator(
{
Home: HomeScreen,
Components: ComponentsScreen,
},
{
initialRouteName: "Components",
defaultNavigationOptions: {
title: "App",
}
}
);
export default createAppContainer(navigator);
HomeScreen.js
import React from 'react';
import { Text, StyleSheet } from 'react-native';
const HomeScreen = () => {
return <Text style={styles.text}>ProjectWherewoof</Text>
};
const styles = StyleSheet.create({
text: {
fontSize: 30,
},
});
export default HomeScreen;
ComponentsScreen.js
import { Text, StyleSheet, View } from "react-native";
const ComponentsScreen = () => {
const greeting = <Text>Getting Started with React Native</Text>;
const myname = 'Arturo';
return (
<View>
<Text style={styles.greetingStyle}>{greeting}</Text>
<Text style={styles.nameStyle}>My name is {myname} !!!</Text>
</View>
);
};
const styles = StyleSheet.create({
greetingStyle: {
fontSize: 45,
},
nameStyle: {
fontSize: 20,
}
});
export default ComponentsScreen;
ListScreen.js
import React from 'react';
import { Text, StyleSheet } from 'react-native';
const ListScreen = () => {
return <Text>List Screen</Text>;
};
const styles = StyleSheet.create({});
export default ListScreen;
Folder Structure:
Folder Structure snapshot

You're missing a slash in import ListScreen from ".src/screens/ListScreen";. .src is not a directory in your project.
It should be import ListScreen from "./src/screens/ListScreen"; (or just "src/screens/ListScreen";)

Related

Error: Image: asset with ID "1" could not be found. Please check the image source or packager

I'm new to react native and I'm following a tutorial to learn the language.
I'm now trying to set a background image using ImageBackground.
WelcomeScreen.js:
import React from 'react';
import { ImageBackground, StyleSheet } from 'react-native-web';
function WelcomeScreen(props) {
return (
<ImageBackground
style={styles.background}
source={require("../assets/background.jpg")}
></ImageBackground>
);
}
const styles = StyleSheet.create({
background: {
flex: 1
}
})
export default WelcomeScreen;
App.js
import React from 'react';
import { View } from 'react-native';
import WelcomeScreen from './app/screens/WelcomeScreen';
export default function App() {
return (
<WelcomeScreen />
);
}
Now I get this error: Error: Image: asset with ID "1" could not be found. Please check the image source or packager.
I have a app folder in in my projectfolder. In this app folder I have the assets folder and a screens folder. The WelcomeScreen.js is in the screens folder. The background.jpg is in the assets folder and the App.js is in the main/project folder.
I can't seem to find any way to fix this error.
Try changing your module import from react-native-web to just react-native
WelcomeScreen.js
import React from "react";
import { ImageBackground, StyleSheet } from "react-native";
function WelcomeScreen(props) {
return (
<ImageBackground
style={styles.background}
source={require("../assets/background.png")}
></ImageBackground>
);
}
const styles = StyleSheet.create({
background: {
flex: 1,
},
});
export default WelcomeScreen;
You do not need to add ./app to your WelcomeScreen.js file path
App.js
import WelcomeScreen from "./screens/WelcomeScreen";
export default function App() {
return <WelcomeScreen />;
}
Hope this helps!

Application not loaded after upgrade from React-navigation 4 to React-Navigation 6

after upgrade from React-navigation 4 to React-navigation 6 the default imports cause undefined errors when used for assignments.
The Application uses expo, Expo SDK version is 44.
This error occurs when opening the application
Application error
RoutesNavigators.js
import * as React from 'react';
import { NavigationContainer } from '#react-navigation/native';
import { createNativeStackNavigator } from '#react-navigation/native-stack';
import ConfigsLoading from './screens/commons/configs_loading';
const Stack = createNativeStackNavigator();
const RoutesNavigator = () => (
<NavigationContainer>
<Stack.Navigator initialRouteName="ConfigsLoading" screenOptions={{ headerShown: false }}>
<Stack.Screen name="ConfigsLoading" component={ConfigsLoading} />
</Stack.Navigator>
</NavigationContainer>
);
export default RoutesNavigator;
configs_loading / index.jsx
/* eslint-disable no-constant-condition */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { View, ActivityIndicator, Text } from 'react-native';
import { connect } from 'react-redux';
import { translate } from 'react-i18next';
import lojas from '../../features/lojas';
import { styles } from './styles';
import pushTokens from '../../../infra/push_tokens';
import usuarios from '../../features/usuario';
import campanhas from '../../features/campanhas';
class ConfigsLoading extends Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<View style={styles.container}>
<ActivityIndicator size="large" color="#999999" />
<Text>{this.props.t('commons:carregando')}</Text>
</View>
);
}
}
ConfigsLoading.propTypes = {
navigation: PropTypes.object.isRequired,
credenciais: PropTypes.object.isRequired,
recuperarLojaFavorita: PropTypes.func.isRequired,
setarLojaCorrente: PropTypes.func.isRequired,
recuperarCredencial: PropTypes.func.isRequired,
aceitarTermosUso: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
criarTokenUsuario: PropTypes.func.isRequired,
pushToken: PropTypes.string,
recuperarCampanhaVigente: PropTypes.func.isRequired,
};
ConfigsLoading.defaultProps = {
pushToken: undefined,
};
const mapStateToProps = state => ({
salvandoLojaFavorita: lojas.selectors.obterSalvandoLojaFavorita(state),
pushToken: pushTokens.selectors.obterToken(state),
credenciais: usuarios.selectors.obterCredencial(state),
aceitandoTermosUso: usuarios.selectors.obterAceitandoTermosUso(state),
excluidoCredencialUsuario: usuarios.selectors.obterExcluindoCredencial(state),
});
const obj = translate(['common'], { wait: true })(ConfigsLoading);
export default connect(mapStateToProps, {
...lojas.actions, ...pushTokens.actions, ...usuarios.actions, ...campanhas.actions,
})(obj);
lojas / index.js
import Container from './components/Container';
import Lista from './components/Lista';
import * as constants from './constants';
import * as actions from './actions';
import * as selectors from './selectors';
import reducer from './reducer';
export default {
Container,
Lista,
reducer,
constants,
actions,
selectors,
};
pushTokens, campanhas and usuarios files has te same export as the lojas file
i have the following plugins in my babel.config.js
"babel-plugin-module-resolver",
"react-native-reanimated/plugin"

How Do you access function props in your class component?

I am trying to set up react redux, also i have set it but I am getting an error TypeError: _this.props.showLoader is not a function. (In '_this.props.showLoader(true)', '_this.props.showLoader' is undefined).
this.props.showLoader(true)
This function has been defined in Action.js file you can find it below.
This error comes whenever I try to call a function from Root.js file, you can find it below.
Below is the code what I have done so far:->
I have App.js file in which I have set for provider and store
import React, { Component } from 'react';
import {StyleSheet, View, Text} from 'react-native';
import {Provider} from 'react-redux';
import store from './src/redux/Store'
import Root from './src/root/Root'
function App() {
return (
<Provider store={store}>
<View style={localStyles.container}>
<Root/>
</View>
</Provider>
);
}
export default App;
const localStyles = StyleSheet.create({
container: {
flex: 1,
},
});
This is the Navigation Route File
import React from 'react'
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import TutorialSwipeScreen from '../components/viewcontrollers/onboarding/TutorialSwipeScreen'
const Stack = createStackNavigator();
function goStack() {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false
}}
>
<Stack.Screen name="Login" component={Login Screen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default goStack;
My Root.js file
where I am trying to this.props.showLoader it gives me error
import React, {Component} from 'react'
import {View, StyleSheet, Text} from 'react-native'
import NavigationRoute from './NavigationRoutes'
import DeviceInfo from 'react-native-device-info'
class Root extends Component {
constructor(props) {
super(props)
console.warn('props=', this.props)
}
componentDidMount() {
this.call()
}
call = () => {
this.props.showLoader(true)
}
render () {
return (
<View style={styles.rootContainer}>
<NavigationRoute/>
</View>
)
}
}
export default Root;
const styles = StyleSheet.create({
rootContainer: {
flex: 1,
}
});
My RootContainer.js File
import {bindActionCreators} from 'redux'
import {connect} from 'react-redux'
import * as Actions from '../redux/Actions'
import Root from './Root'
function mapStateToProps(state) {
return {
shouldShowLoader: state.dataReducer._showLoader,
shouldChangeCounting: state.dataReducer.counter
}
}
function mapDispatchToProps(dispatch) {
const mergedActions = Object.assign({}, Actions);
return bindActionCreators(mergedActions, dispatch)
}
export default connect(mapStateToProps, mapDispatchToProps)(Root);
My Store.js file
import {createStore} from 'redux'
import reducers from './RootReducer'
export default createStore(reducers);
My RootReducer.js
import {combineReducers} from 'redux'
import dataReducer from './reducers/Reducer'
const rootReducer = combineReducers ({
dataReducer,
})
export default rootReducer;
My Action.js file which has a function showLoader(bool) which I try to call from Root.js which gives me an error as I have quoted above.
export const DISPLAY_LOADER = 'DISPLAY_LOADER';
export const REFRESH = 'REFRESH';
export const COUNTER = 'COUNTER';
export function showLoader(bool) {
return {
type: DISPLAY_LOADER, data: bool,
};
}
export function refresh() {
return {
type: REFRESH, data: true,
};
}
export function counting(count) {
return {
type: COUNTER, data: count
}
}
And Finally Reducer.js file code goes here
import { DISPLAY_LOADER, REFRESH, WELCOME_POPUP, LOGIN_RELOAD, MESSAGE_POPUP, LOGOUT, COUNTER} from '../Actions';
const initialState = {
counter: 5,
_showLoader: false,
_showMessagePopup: false,
_loginReload: false,
_refresh: false,
_heading: 'Message Heading',
_message: 'PWG Custom Message',
}
const dataReducer = (state = initialState, action) => {
switch(action.type) {
case DISPLAY_LOADER: {
return {...initialState, _showLoader: action.data}
}
case REFRESH: {
return {...initialState, _refresh: action.data}
}
case LOGOUT: {
return {...initialState, _refresh: true}
}
case COUNTER: {
return {...initialState, counter: action.data}
}
default: {
return state;
}
}
}
export default dataReducer;
So where my mistake is I am not able to find with what lines of code I am receiving error at my end. Please help. Also I am new to react native please bear with me.
Thanks
I have got the answer, I am answering my own post.
In the App.js File You need to import
RootContainer
instead of
Root
That’s it and it works Voila.
import RootContainer from './src/root/RootContainer'
I see that your showLoader tied to your redux reducer.
what i can suggest you, you should return state not initialState in your reducer. Basically what youre doing is after each change of state in redux, everything else will go back to its initialState but not the changed state itself.
You also didn't pass props showLoader to your Root component. If your intention is using showLoader as a setState function for your Root component, you should define the function in your mapDispatchToProps in your connect function

Getting Error: The component for route 'Books' must be a React component. For example: import MyScreen from './MyScreen';

Getting the following error:
The component for route 'Books' must be a React component. For example:
import MyScreen from './MyScreen';
But i'm not even using react-navigation in this screen.
https://snack.expo.io/#ganiyat1/colorful-thrills
import React, { useState } from 'react';
import { StyleSheet, SafeAreaView } from 'react-native';
import MaterialTabs from 'react-native-material-tabs';
const Book = () => {
const [selectedTab, setSelectedTab] = useState(0);
return (
<SafeAreaView style={styles.container}>
<MaterialTabs
items={['New Releases', 'All', 'BOM']}
selectedIndex={selectedTab}
onChange={setSelectedTab}
barColor="#1fbcd2"
indicatorColor="#ff914d"
activeTextColor="white"
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
You are not exporting the Book component.
In the book component, either add export default Book to the bottom, or do export const Book.... You also need to change the import to for a default export
import Book from './components/Books';
or
import { Book } from './components/Books';
if you do a named export (export const Book).

Navigation: project.testscreen registration result is 'undefined'

I've just installed react-native-navigation using the installation guides provided on https://wix.github.io/react-native-navigation/#/installation-ios and the usage guide https://wix.github.io/react-native-navigation/#/usage.
I've followed these and checked out multiple example apps, but I cannot figure out why my screens won't register.
The error I receive is: console.error: "Navigation: project.testscreen registration result is 'undefined'".
The registerScreens is called and the registration is completed, but it seems like the registration results to undefined.
index.js
import App from './src/app'
const app = new App();
app.js
import { Navigation } from 'react-native-navigation';
import { registerScreens } from './screens';
registerScreens();
Navigation.startTabBasedApp({
tabs: [{
label: 'Test',
screen: 'project.testscreen',
title: 'Test',
}]
});
screens.js
import { Navigation } from 'react-native-navigation'
import { TestScreen } from './components/testScreen'
export function registerScreens() {
Navigation.registerComponent('project.testscreen', () => TestScreen)
}
testScreen.js
import React, { Component } from 'react';
import { Text, View } from 'react-native';
class TestScreen extends Component {
render() {
return (
<View>
<Text>Hi</Text>
</View>
)
}
}
export default TestScreen
react-native: 0.55.4
react-native-navigation: latest (1.1.479)
change
import { TestScreen } from './testScreen'
to
import TestScreen from './testScreen'
Because TestScreen exports as default