Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Fix path mapping typescript in React Native

$
0
0

I'm trying to use typescript path mapping to improve my imports. But I have an error:

@UI/MainHeader could not be found within the project or in these directories:node_modules

So I updated my tsconfig

..."baseUrl": "./",    /* Specify the base directory to resolve non-relative module names. */"paths": {"@UI/*": ["./src/view/UI/*"      ],"@components/*": ["./src/view/components/*"      ],"@icons/*": ["./src/view/icons/*"      ]    },...

And also updated babel.config with module resolver plugin.

module.exports = function (api) {  api.cache(true);  return {    presets: ['module:metro-react-native-babel-preset'],    plugins: [      ['module-resolver'],      {        extensions: ['.js','.jsx','.ts','.tsx','android.js','android.tsx','ios.js','ios.tsx',        ],        root: ['./'],        alias: {'@UI/*': ['./src/view/UI/*'],'@components/*': ['./src/view/components/*'],'@icons/*': ['./src/view/icons/*'],        },      },    ],  };};

But after all I still have an error. So what I can do to solve it?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>