microsoft / appcenter-cli

Command-line Interface (CLI) for Visual Studio App Center
https://appcenter.ms/
MIT License
582 stars 235 forks source link

[React Native | Hermes] Code Push for Hermes-Enabled Apps in Monorepos #1170

Closed agreea closed 5 months ago

agreea commented 3 years ago

We have a React Native Android app within a monorepo, where the react-native package installs in the root-level node_modules. Currently, when attempting to code push for a React Native app in a monorepo, the process fails when attempting to convert the JS bundle to byte code via Hermes (see output below).

Converting JS bundle to byte code via Hermes, running command:

node_modules/hermesvm/osx-bin/hermes -emit-binary -out /var/folders/q3/fzyknkyx3cv21d6lxj0k3vnw0000gn/T/code-push2020113-30003-1c4vji1.e8hb/CodePush/index.android.bundle.hbc /var/folders/q3/fzyknkyx3cv21d6lxj0k3vnw0000gn/T/code-push2020113-30003-1c4vji1.e8hb/CodePush/index.android.bundle
node:events:304
      throw er; // Unhandled 'error' event
      ^

Error: spawn node_modules/hermesvm/osx-bin/hermes ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:269:19)
    at onErrorNT (node:internal/child_process:465:16)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:275:12)
    at onErrorNT (node:internal/child_process:465:16)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node_modules/hermesvm/osx-bin/hermes',
  path: 'node_modules/hermesvm/osx-bin/hermes',
  spawnargs: [
    '-emit-binary',
    '-out',
    '/var/folders/q3/fzyknkyx3cv21d6lxj0k3vnw0000gn/T/code-push2020113-30003-1c4vji1.e8hb/CodePush/index.android.bundle.hbc',
    '/var/folders/q3/fzyknkyx3cv21d6lxj0k3vnw0000gn/T/code-push2020113-30003-1c4vji1.e8hb/CodePush/index.android.bundle'
  ]
}

The problem is this function which assumes hermes-engine (or hermesvm) will be found within the project's node_modules. The react-native-codepush package threw errors with similar causes in the build process. These were solved by setting the nodeModulesPath in our project's gradle.properties.

An easy solution would be checking the app's gradle file for hermesCommand or nodeModulesPath values (as code push does here to determine whether to run hermes in the first place). This would also bring the code push cli behavior more in line with the code push package's build behavior. Then, perhaps, we could add some documentation about how AppCenter behaves with Hermes-enabled apps, as others have run into issues 1 2 2.

I tried implementing this with the intent of opening a PR but wasn't able to build appcenter-cli locally.

Also note that the cli doesn't detect that we're on react-native@^0.63.0 because it's using hermesvm rather than hermes-engine. This may have something to do with react-native being installed at root node_modules.

Details: appcenter cli: 2.7.3 react-native: 0.63.3 hermes-engine: 0.5.0 react-native-code-push: 6.4.0

DmitriyKirakosyan commented 5 months ago

Closing as fixed.