I'm setting up react native project with typescript, and I was struggling with the import setup for days, I'm having this error when importing a component that I write myself, not from library:
error: Error: Unable to resolve module screens/BulletinScreen from C:\Development_Projects\atlas\src\navigation\AppNavigator.tsx: screens/BulletinScreen could not be found within the project or in these directories: node_modules 6 | import {NavigationContainer} from '@react-navigation/native'; 7 | import React from 'react';> 8 | import BulletinScreen from 'screens/BulletinScreen'; | ^ 9 | import StudyInfoScreen from 'screens/StudyInfoScreen'; 10 | import BottomTabBar from './components/BottomTabBar'; 11 | import screenKey from './ScreenKey';
Any help will be appreciated, here is my babel.config.js
:
module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ ['module-resolver', { root: ['./'], alias: { assets: './src/assets', components: './src/components', navigation: './src/navigation', redux: './src/redux', screens: './src/screens', types: './src/types', utils: './src/utils', }, }, ], ],};
And tsconfig.json
:
{"extends": "@tsconfig/react-native/tsconfig.json","compilerOptions": {"baseUrl": ".","paths": {"assets/*": ["./src/assets/*"],"components/*": ["./src/components/*"],"navigation/*": ["./src/navigation/*"],"redux/*": ["./src/redux/*"],"screens/*": ["./src/screens/*"],"types/*": ["./src/types/*"],"utils/*": ["./src/utils/*"] },"typeRoots": ["@types", "node_modules/@types"],"skipLibCheck": true },"include": ["./src", "App.tsx"]}