Reputation: 798
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?
Upvotes: 2
Views: 3756
Reputation: 1814
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 :)
Upvotes: 1