Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to resolve path alias? #122

Open
ice-cap0 opened this issue Aug 5, 2023 · 5 comments
Open

Option to resolve path alias? #122

ice-cap0 opened this issue Aug 5, 2023 · 5 comments

Comments

@ice-cap0
Copy link

ice-cap0 commented Aug 5, 2023

Error: Unable to resolve module @/auth/my.device.slice from

@ path alias is defined in tsconfig.json

  "compilerOptions": {
    ...
    "paths": {
      "@/*": ["src/*"]
    }
@frankcalise
Copy link

Also running into this

@percy507
Copy link

Same problem

@IjzerenHein
Copy link
Owner

Could you provide a reproducible example?

@frankcalise
Copy link

@IjzerenHein you can just ignite a new app, we have it running TS paths by default:

npx ignite-cli@latest new pizza-visualizer --packager=bun --yes
cd pizza-visualizer
npx react-native-bundle-visualizer`

This will be an Expo Go application and you'll receive an error like the following:

Error: Unable to resolve module app/screens from /Users/fcalise/code/pizza-visualizer/app/navigators/AppNavigator.tsx: app/screens could not be found within the project or in these directories:
  node_modules
  15 | import React from "react"
  16 | import { useColorScheme } from "react-native"
> 17 | import * as Screens from "app/screens"
     |                           ^
  18 | import Config from "../config"
  19 | import { useStores } from "../models"
  20 | import { DemoNavigator, DemoTabParamList } from "./DemoNavigator"
    at ModuleResolver.resolveDependency (/Users/fcalise/code/pizza-visualizer/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:139:15)

If you want the native directories available, tack on --workflow=prebuild to the command above.

@gabimoncha
Copy link

gabimoncha commented Dec 30, 2023

In order to make it work for path alias, you need to add the alias also inside babel module-resolver plugin. This is my config using expo and typescript

babel.config.js

module.exports = function (api) {
  api.cache(true);
  const plugins = [
    'expo-router/babel',
    [
      'module-resolver',
      {
        alias: {
          '~': '.',
        },
      },
    ],
  ];

  plugins.push('react-native-reanimated/plugin');

  return {
    presets: ['babel-preset-expo'],
    plugins,
  };
};

tsconfig.json

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants