1

I've been working with React Native recently trying to produce a mobile application. I'm planning on using the react-navigation plugin in order to allow the user to change screens. However, when I import the screen (ScreenOne.js) into the App.js. However, I get the error:

Unable to resolve module `screens/ScreenOne` from `C:\Users\User\Desktop\Projects\LRAPPMAIN\App.js`: Module `screens/ScreenOne` does not exist in the Haste module map

This is strange as I only get this error when importing it. My code is as follows:

ScreenOne.js

import React, {Component} from 'react';
import {Button, Text, View} from 'react-native';

export class ScreenOne extends Component {
render() {
    return (
        <View>
            <Text>This is the Settings screen</Text>
            <Button title="Home"/>
        </View>
        )
    };
export default ScreenOne;

App.js

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';

import ScreenOne from 'screens/ScreenOne'

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
   backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

Is there anything I'm doing wrong here?

JPanda
  • 319
  • 3
  • 12
  • Possible duplicate of [Unable to resolve module...does not exist in the haste module map](https://stackoverflow.com/questions/50844133/unable-to-resolve-module-does-not-exist-in-the-haste-module-map) – Paras Oct 17 '18 at 21:19

1 Answers1

0

When you import something on react and don't use relative paths, it will always look inside your node-modules folder.

What you probably want to do on your App.js file is

import ScreenOne from './screens/ScreenOne';

This way, react will not look for the file relative to your current one.

also

you forgot to close one curly bracket on your ScreenOne.js file.

Sergio Moura
  • 4,888
  • 1
  • 21
  • 38