Skip to content

Cannot find module 'react-native/cli' #995

@lachenmayer

Description

@lachenmayer

Environment

react-native info output
λ yarn exec react-native info
yarn exec v1.22.0
info Fetching system and libraries information...
System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
    Memory: 52.27 MB / 16.00 GB
    Shell: 3.0.2 - /usr/local/bin/fish
  Binaries:
    Node: 12.16.0 - /var/folders/z8/xq1r3qcd7szbpx1_77xsgpqc0000gn/T/yarn--1582222260147-0.32330923283802093/node
    Yarn: 1.22.0 - /var/folders/z8/xq1r3qcd7szbpx1_77xsgpqc0000gn/T/yarn--1582222260147-0.32330923283802093/yarn
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
    Android SDK:
      API Levels: 23, 25, 26, 27, 28
      Build Tools: 23.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.2, 27.0.3, 28.0.3
      System Images: android-27 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.1 AI-173.4720617
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: ~16.9.0 => 16.9.0 
    react-native: ~0.61.5 => 0.61.5
✨  Done in 4.79s.

Description

Hi folks, this issue is very closely related to #406, but I decided to open a new issue for it since it may require a different solution altogether, and that issue is closed.

In short, @react-native-community/cli-platform-android is breaking our builds on Appcenter (cc @kinigitbyday #406 (comment) ), using the following versions:

λ yarn list --pattern @react-native-community/cli
yarn list v1.22.0
├─ @react-native-community/[email protected]
├─ @react-native-community/[email protected]
├─ @react-native-community/[email protected]
├─ @react-native-community/[email protected]
├─ @react-native-community/[email protected]
└─ @react-native-community/[email protected]

The exact failure logged by Appcenter (aka Azure DevOps) is the following:

[command]/Users/runner/runners/2.165.0/work/1/s/app/android/gradlew -DAPPCENTER_KEYSTORE_PASSWORD=*** -DMOBILECENTER_KEYSTORE_PASSWORD=*** -DAPPCENTER_KEY_ALIAS=*** -DMOBILECENTER_KEY_ALIAS=*** -DAPPCENTER_KEY_PASSWORD=*** -DMOBILECENTER_KEY_PASSWORD=*** -DAPPCENTER_BUILD_VERSION=14 -DMOBILECENTER_BUILD_VERSION=14 -p app/android clean :app:assembleRelease :app:bundleRelease
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
Gradle 5.5
:ReactNative:Unexpected empty result of running '[node, -e, console.log(require('react-native/cli').bin);]' command.
:ReactNative:Running '[node, -e, console.log(require('react-native/cli').bin);]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/runner/runners/2.165.0/work/1/s/app/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 170

* What went wrong:
A problem occurred evaluating script.
> internal/modules/cjs/loader.js:984  throw err;  ^Error: Cannot find module 'react-native/cli'Require stack:- /Users/runner/runners/2.165.0/work/1/s/[eval]    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:981:15)    at Function.Module._load (internal/modules/cjs/loader.js:863:27)    at Module.require (internal/modules/cjs/loader.js:1043:19)    at require (internal/modules/cjs/helpers.js:77:18)    at [eval]:1:13    at Script.runInThisContext (vm.js:120:20)    at Object.runInThisContext (vm.js:311:38)    at Object.<anonymous> ([eval]-wrapper:10:26)    at Module._compile (internal/modules/cjs/loader.js:1157:30)    at evalScript (internal/process/execution.js:94:25) {  code: 'MODULE_NOT_FOUND',  requireStack: [ '/Users/runner/runners/2.165.0/work/1/s/[eval]' ]}

There is a comment in the affected Gradle file Sometimes Gradle can be called outside of the JavaScript hierarchy (-p flag) which seems related. Appcenter calls this with -p app/android.

We have our RN app in a directory called app/ in our repo, and you can see from the stacktrace that the eval is executed from the root directory of the repo instead of within app/ or app/android as I would expect.

I have tried various versions of @react-native-community/cli-platform-android, and it seems that the issue was introduced by this commit which removes npx, which was released in 3.1.0: b4b0854

We hotfixed this for now by pinning @react-native-community/cli-platform-android to the latest version before 3.1.0 by adding the following to our package.json:

  "resolutions": {
    "@react-native-community/cli-platform-android": "~3.0.0"
  }

Hope this helps, let me know if I can help test any solution to this :)
Thank you!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions