infinitered / ignite

Infinite Red's battle-tested React Native project boilerplate, along with a CLI, component/model generators, and more! 9 years of continuous development and counting.
MIT License
17.74k stars 1.4k forks source link

Cannot run Ignite RN app in yarn monorepo #2715

Open mausic opened 4 months ago

mausic commented 4 months ago

Describe the bug

Hi! Cannot run Ignite RN app on iOS in yarn monorepo (yarn v1.22.22). Steps to reproduce:

  1. Start a monorepo with npx create-turbo@latest select yarn as a package manager

  2. cd apps

  3. Ignite RN project npx ignite-cli@latest new pizza-app with following options:

    Screenshot 2024-07-26 at 16 00 54
  4. cd pizza-app

  5. yarn install

  6. According to expo monorepo guidelines:

    • create index.js with the following content:
      
      import { registerRootComponent } from "expo";

import App from "./App";

registerRootComponent(App);

-  update `package.json` (set `"main": "index.js",`)
-  update `metro.config.js` as in [expo guidelines](https://docs.expo.dev/guides/monorepos/#modify-the-metro-config)
7. `npx pod-install`
8. `yarn ios`
9. Observe infinite errors:
```bash
ERROR  TypeError: Cannot assign to property 'username' which has only a getter, js engine: hermes
 ERROR  TypeError: Cannot assign to property 'username' which has only a getter, js engine: hermes
 ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 2 and callID 1 for module <unknown>. Args: '[{"app_state":"active"}]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 18 and callID 9 for module <unknown>. Args: '[{"app_state":"active"}]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 41 and callID 20 for module <unknown>. Args: '[0]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 45 and callID 22 for module <unknown>. Args: '[1]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 49 and callID 24 for module <unknown>. Args: '[2]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 63 and callID 31 for module <unknown>. Args: '[3]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 77 and callID 38 for module <unknown>. Args: '[4]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 81 and callID 40 for module <unknown>. Args: '[5]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 85 and callID 42 for module <unknown>. Args: '[6]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 89 and callID 44 for module <unknown>. Args: '[7]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 117 and callID 58 for module <unknown>. Args: '[8]', js engine: hermes
 ERROR  Invariant Violation: No callback found with cbID 123 and callID 61 for module <unknown>. Args: '[9]', js engine: hermes
...

[!IMPORTANT] Sample project: https://github.com/mausic/turborepo-ignite

Ignite version

9.7.1

Additional info

npx ignite-cli doctor
System
  platform           darwin
  arch               arm64
  cpu                10 cores     Apple M1 Pro
  directory          pizza-app    /Users/mausic/Projects/turborepo-rn/apps/pizza-app

JavaScript (and globally-installed packages)
  node                 20.11.1                                   /Users/mausic/.nvm/versions/node/v20.11.1/bin/node
  npm                  10.8.1                                    /Users/mausic/.nvm/versions/node/v20.11.1/bin/npm
    @aws-amplify/cli   12.10.1
    @microsoft/rush    5.93.1
    @nestjs/cli        9.1.4
    apollo             2.34.0
    aws-cdk            2.141.0
    corepack           0.10.0
    eas-cli            7.5.0
    graphql            16.6.0
    npm                10.8.1
    pnpm               7.27.1
    rush               0.0.2
    ts-node            10.9.1
    typescript         4.9.4
    vercel             34.1.9
    yarn               1.22.22
  yarn                 1.22.22                                   /Users/mausic/.nvm/versions/node/v20.11.1/bin/yarn
    create-amplify     1.0.1
    create-next-app    13.0.7
    create-turbo       2.0.9
    create-vite        5.2.3
  pnpm                 9.5.0                                     /Users/mausic/Library/pnpm/pnpm
                       <no pnpm global package info available>
  bun                  -                                         not installed
  expo                 51.0.22                                   managed

Ignite
  ignite-cli         9.7.1        /Users/mausic/.npm/_npx/e31027f3785124a8/node_modules/.bin/ignite
  ignite src         build        /Users/mausic/.npm/_npx/e31027f3785124a8/node_modules/ignite-cli/build

Android
  java               -            not installed
  android home       -            undefined

iOS
  xcode              15.4
  cocoapods          1.11.3       /Users/mausic/.rvm/gems/ruby-2.7.2/bin/pod

Tools
  git                git version 2.39.3 (Apple Git-146)   /usr/bin/git
mausic commented 4 months ago

[!TIP] The issue is resolved if we Ignite the second RN app in the same monorepo.

Steps to reproduce:

  1. Take the codebase from original issue or sample repo

  2. cd apps

  3. npx ignite-cli@latest new dummy-app using the following options:

    Screenshot 2024-07-26 at 16 20 19
  4. yarn install

  5. cd pizza-app

  6. npx pod-install

  7. yarn ios

  8. Success!

So, I'm assuming, the issue might be related to yarn packages management (and probably hoisting) and pods management.

I am not sure that this is the Ignite team responsibility, however, I would be thankful for any advise on resolving the issue without creating the second RN app.

frankcalise commented 3 months ago

yeah we have an open item for #1981 - I will discuss it with @trevor-coleman and @joshuayoes to see if we can't debug your repro example, thanks for setting that up

fpena commented 3 months ago

Yes, we're working on a mono repo guide / recipe. It will be released alongside v10.

cc: @frankcalise