cli: Autolinking fails on Windows

Environment

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 9.61 GB / 15.89 GB
  Binaries:
    Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  SDKs:
    Android SDK:
      Android NDK: 18.1.5063045
  IDEs:
    Android Studio: Version  3.3.0.0 AI-182.5107.16.33.5264788

Output of react-native --version:

react-native-cli: 2.0.1
react-native: 0.60.0

Description

This is the error I am getting while running react-native run-android or .\gradlew app:installDebug:

:ReactNative:Cannot run program "./node_modules/.bin/react-native" (in directory "C:\Users\thecodrr\Source\Repos\Mysue\android\.."): CreateProcess error=2, The system cannot find the file specified
:ReactNative:Automatic import of native modules failed.

> Configure project :app
:ReactNative:Cannot run program "./node_modules/.bin/react-native" (in directory "C:\Users\thecodrr\Source\Repos\Mysue\android\.."): CreateProcess error=2, The system cannot find the file specified
:ReactNative:Automatic import of native modules failed.

I tried running the gradlew app:installDebug command on Git Bash but still got the same error.

Reproducible Demo

  1. Create a new project using react-native init
  2. Run yarn add react-native-track-player@latest
  3. Run yarn react-native run-android

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 80 (50 by maintainers)

Most upvoted comments

Let’s get some facts straight:

  1. @react-native-community/cli is a dependency of react-native. That makes it a “transitive dependency” of your project.
  2. react-native-cli is a global package, we discourage to use it, it’s kind of a proxy to @react-native-community/cli, but it’s a bit more complicated that that.
  3. We update the CLI independently of React Native itself.

Now that we know the facts:

Solution is to update your CLI version:

  1. If you use lock files (yarn.lock, package-lock.json) - find the @react-native-community/cli entry, remove it, run yarn install/npm install once again
    1. If you don’t use lock files – you should. But in such case, remove node_modules and run npm install again.
  2. run npm list @react-native-community/cli or yarn list @react-native-community/cli and verify you’re on the latest version (above 2.1.0).

After performing these steps you should be on the latest CLI version. Feel free to do it once in a while, because we release often.

yarn or npx both don’t work via the java exec.

Maybe java exec doesnt take PATH into consideration? Btw why is this important?

Because that’s what’s happening behind the scenes in the native_modules.gradle. Autolinking basically gets your packages through this command.

Yea, sorry for the confusion. We’re in a big transition period, things are moving fast, but we’re heading in a good direction, even if at times it seems like things get worse. It’s only temporary 😃

@mi5ha I don’t think they updated it correctly/fully after 0.60 release and after npx was added.

@theweavrs @thymikee yes! I removed yarn.lock and run yarn again. this time, the error message gone.

@theweavrs If you follow what is written on official site you get the solution that doesn’t run, just saying… 😃

@zenz do what @thymikee said and if it still doesn’t work, try adding these in your package.json under devDependencies:

    "@react-native-community/cli": "^2.1.0",
    "@react-native-community/cli-platform-android": "^2.1.0",
    "@react-native-community/cli-platform-ios": "^2.1.0",

Afterwards, do yarn or npm i

@zenz @mi5ha @thymikee created one at #484

Works for me. The time for command execution varies though. Sometimes, it completes in a few seconds and sometimes it takes exactly a minute. Currently, my internet is having issues so maybe it’s because of that?

@thymikee from the JDK docs:

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

So it seems we will need to read the output continuously using I/O stream classes. This article may be the solution.