React Native platform specific import only works with relative paths

Viewed 56

I have a platform specific component split into 2 files:

src/components/Foo/Foo.android.tsx
src/components/Foo/Foo.ios.tsx

I want to import it in a file:

src/screens/Login.tsx

using:

import Foo from "components/Foo/Foo"

Non-platform specific files can be imported that way because I have setup this custom tsconfig for my project:

"paths": {                                /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
  "*": ["src/*"],
  "@components/*": ["src/components/*"],
},

However RN bundler does not find the file. I can only import it using relative paths like this:

import Foo from "../../components/Foo/Foo"

I already tried to change my @components paths config to:

"@components/*": ["src/components/*", "src/components/*.android", , "src/components/*.ios"],

without success.

Any idea why the RN bundler is not able to find the import using components import path notation?

0 Answers
Related