Skip to content

Path not recognized when building - Unable to resolve module ... could not be found within the project #396

@GlisboaDev

Description

@GlisboaDev

I'm trying to put together a monorepo project with react-native, typescript and get relative imports working and keep getting the following error:
Unable to resolve module `@screen/XXX` from `packages/project1/src/...`: @screen/XXX could not be found within the project
I noticed #276 sounds similar to what I'm experiencing, but I don't have any env related configuration and I can reproduce it even in the debug environment.

First, my mono repo structure is:

-root
--packages
----project1
------src
----project2
------src
...

I managed to get it all working on development environment, but have some weird behaviours happening:

  • If I run yarn workspace project1 run start // yarn workspace project1 run ios everything works fine as mentioned, but running only run yarn workspace project1 run ios fails to load the path giving the error above (likely because the packager is started from Xcode with a different working directory?)
  • If I run./gradlew assemble... from the android folder, it also gives the same error above.
  • If I corrupt the babel.config.js file (say add {!@#$: !@#, ...}) and run ./gradlew assemble nothing seems to change
babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'module-resolver',
      {
        root: ['./packages/project1/src/'],
        extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'],
        alias: {
          '@': './packages/project1/src',
          '@screen': './packages/project1/src/screen',
          '@util': './packages/project1/src/util/*',
          '@nav': './packages/project1/src/navigation/*',
          '@component': './packages/project1/src/component/*',
        },
      },
    ],
    'babel-plugin-styled-components',
  ],
};

Resolver version: "babel-plugin-module-resolver": "^4.0.0",

Any ideas on what might have been happening or what am I missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions