Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Native (Typescript) Absolute path unable to resolve module

I have just created a new project and I am trying to setup an absolute path by following this post: https://medium.com/geekculture/making-life-easier-with-absolute-imports-react-in-javascript-and-typescript-bbdab8a8a3a1

I have followed the steps as close as I can but can not get this to work in my simulator. (Visually there are no errors when looking at my code in IDE)

Terminal error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

eslint-config.json

{
  "eslintConfig": {
    "extends": ["react-app", "airbnb"],
    "settings": {
      "import/resolver": {
        "node": {
          "paths": ["src"],
          "extensions": [".js", ".jsx", ".ts", ".tsx"]
        }
      }
    }
  }
}

tsconfig.json

{
  "extends": "@tsconfig/react-native/tsconfig.json",     /* Recommended React Native TSConfig base */
  "compilerOptions": {
    "skipLibCheck": true,                                 /* Skip type checking all .d.ts files. */
    "baseUrl": "src",
  },
}

In this image you can see my file structure, the error on my simulator. And how I am importing it.

enter image description here

I have two exported functions in my Text.tsx
export function Title
&
export function P

Any help is appreciated… Thank you!

>Solution :

I will not suggest you to go with this flow because it’s very confusing.

Suppose you had imported this react/client thing.

  • Is it the npm package that contains subpath
  • Is it my folder structure pathname

So I suggest you to go with the flow that most of the developers are using currently.

import Text from "@/views/Text";

I made one demo for you also, please check https://codesandbox.io/s/sleepy-dew-wn2rsu

Note

  • Use eslint-plugin-import for removing import errors.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading