2

I'm brand new to React Native, and am already stuck at a seemingly obvious problem.

So I get an error

Unable to resolve "src/AppNavigator" from "App.js"

when I try to access my AppNavigator from App.js. Here is my App.js:

import React from 'react';
import { createAppContainer } from 'react-navigation';
import AppNavigator from 'src/AppNavigator';

const App = createAppContainer(AppNavigator);

export default App;

and project structure:

-App.js
-babel.config.js
-index.js (what do you even use this for?)
-app.json
-package.json
-package-lock.json
-src
  |_ AppNavigator.js
  |_ react-native.config.js
  |_ screens
  |   |_ //...
  |_ assets
      |_ //...
-android
  |_ //...
-ios
  |_ //...
-__tests__
  |_ //...
-node_modules
  |_ //...

I've tried solutions outlined in this github thread, among others, but none seem to work (not exactly surprising as any documentation becomes obsolete after 6 months...), so I am stuck!

I've tried replacing src/AppNavigator with ./AppNavigator and ../AppNavigator for good measure, but that didn't work either.

Anyway know what's going on here?

1
  • Please can you write your AppNavigator.js content. May be you forgot export it. Commented Nov 26, 2019 at 6:31

1 Answer 1

1

You forgot to add ./ before the path and also since AppNavigator.js is inside the src you have to write the below import code to run it successfully.
Just replace it with the below code and it will work like a charm....

import AppNavigator from './src/AppNavigator';

Note :- .. will make you to go out of your current directory.

Hope this helps...Thanks :)

Sign up to request clarification or add additional context in comments.

2 Comments

hi @Kc_dev, hope it helps. As a new user, you can upvote the answer as well thanks :)
I already did, but github doesn't reflect it until i have 15 reputation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.