Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 961 Bytes

absolute-path-expo-modules.md

File metadata and controls

38 lines (28 loc) · 961 Bytes

Using absolute import paths with local Expo Modules

When importing an Expo module created using npx create-expo-module --local:

You can use an absolute import path in place of a regular relative import:

import module from "my-module";,

To do this you need to include the paths.* wildcard in your tsconfig file.

{
  "compilerOptions": {
    "paths": {
      "*": ["./modules/*"]
    }
  },
  "extends": "expo/tsconfig.base"
}

And change the metro.config.js file to the following:

// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.nodeModulesPaths = [
  ...defaultConfig.resolver.nodeModulesPaths,
  path.resolve(__dirname, "modules"),
];
module.exports = defaultConfig;