2
votes

I am new to Expo and React Native. I am facing some problems in using absolute paths while importing the modules. I came across the well known babel-plugin-module-resolver plugin but i am unable to use it properly. I did almost everything found on different threads regarding this issue but still i am unable to use absolute paths (with TypeScript) in VS Code. In my expo project I also do not have any .babelrc file instead i have babel.config.js file, I don't know why is it so. What can be the issue? TIA

1
have you solved this? - Thu San
Nope :( still using relative paths - Usman Iftakhar

1 Answers

5
votes

Mine seems to be working with below. Try this

Example expo-typescript project https://github.com/thu-san/expo-typescript-example

babel.config.js

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      [
        'module-resolver',
        {
          extensions: [
            '.js',
            '.jsx',
            '.ts',
            '.tsx',
            '.android.js',
            '.android.tsx',
            '.ios.js',
            '.ios.tsx'
          ],
          root: ['./src']
        }
      ]
    ]
  };
};

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./src",
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    "jsx": "react-native",
    "lib": ["es2017"],
    "module": "es2015",
    "moduleResolution": "node",
    "noEmitHelpers": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "sourceMap": false,
    "strict": true,
    "target": "es2017"
  },
  "exclude": ["node_modules"]
}