Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autolinking fails on Windows #470

Closed
thecodrr opened this issue Jul 4, 2019 · 80 comments · Fixed by #480
Closed

Autolinking fails on Windows #470

thecodrr opened this issue Jul 4, 2019 · 80 comments · Fixed by #480
Labels
bug Something isn't working env: windows

Comments

@thecodrr
Copy link
Contributor

thecodrr commented Jul 4, 2019

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
@thecodrr thecodrr added the bug Something isn't working label Jul 4, 2019
@thymikee
Copy link
Member

thymikee commented Jul 4, 2019

Hey! Thanks for filing this issue. Unfortunately we don't have Windows machines to test on. We used to do node ./node_modules/.bin/react-native config, but we got a report that it doesn't work on Windows, but ./node_modules/.bin/react-native config works. So could you share some more information about that?

@victorwpbastos
Copy link
Contributor

I confirm that ./node_modules/.bin/react-native config works on Windows 10 and node ./node_modules/.bin/react-native config doesn't.

@thymikee
Copy link
Member

thymikee commented Jul 4, 2019

It's already resolved and fixed in @react-native-community/cli@2.0.2, make sure you have it installed (check the lock file)

@thymikee thymikee closed this as completed Jul 4, 2019
@victorwpbastos

This comment has been minimized.

@thymikee

This comment has been minimized.

@victorwpbastos

This comment has been minimized.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 4, 2019

Okay so doing node ./node_modules/.bin/react-native config gives this:

* Where:
Script 'C:\Users\thecodrr\Source\Repos\Mysue\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 182

* What went wrong:
A problem occurred evaluating settings 'Mysue'.
> Text must not be null or empty

And doing node ./node_modules/react-native/cli.js config stops the gradle from proceeding, stucking on this:

<-------------> 0% INITIALIZING [7s]
> Evaluating settings 

In the second case, the node process never exits so cmdProcess.waitFor() keeps waiting and waiting. In the first case, the command only inits the node without executing the command.

Adding a delay of, let's say 5 seconds, with cmdProcess.waitFor(5000, java.util.concurrent.TimeUnit.MILLISECONDS) and command node ./node_modules/react-native/cli.js config executes without a hitch albeit after waiting 5 seconds to get config.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 4, 2019

@thymikee I upgraded to 2.0.2 but the error still persists. I have this command ./node_modules/.bin/react-native config in my native_modules.gradle file.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 4, 2019

@thymikee after deleting node_modules folder, doing yarn cache clean the problem is still there. I tried on Git Bash, Powershell and CMD. And version is 2.0.2. So can we please reopen this?

@thymikee
Copy link
Member

thymikee commented Jul 4, 2019

Sure. But you'll need to help us make it work with your environment. We got signals that it works on some Windows, but looks like not all of them. Help appreciated :)

@thymikee thymikee reopened this Jul 4, 2019
@thymikee
Copy link
Member

thymikee commented Jul 4, 2019

Also check if running this command alone, run from terminal, produces a json output. Maybe it takes too long

@thebylito

This comment has been minimized.

@tmtung144
Copy link

"@react-native-community/cli-tools@^2.0.2": version "2.0.2" resolved "https://registry.yarnpkg.com/@react-native-community/cli-tools/-/cli-tools-2.0.2.tgz#1dc4055f27f1b2fe3d0493959a6fc20467e93fe0" integrity sha512-6OOKrE1Sdq1Lmcdp2K68J5PsG5G80a9USa9I1Kv92wvPHUup6IRt+Dy7E8IZqxmskzC/mlOR62Oh1CB3sFm84g== dependencies: chalk "^1.1.1" lodash "^4.17.5" mime "^2.4.1" node-fetch "^2.5.0"

there is still an error

@linhnguyengts
Copy link

same here

@Riant
Copy link

Riant commented Jul 5, 2019

Windows 10, same error even after node ./node_modules/react-native/cli.js config (got a big json), and ./node_modules/react-native config which got a small json.

And the I am sure the cli version is 2.0.2.

Error:

The system cannot find the file specified, ... Automatic import of native modules failed

...
info Installing the app...
:ReactNative:Cannot run program "./node_modules/.bin/react-native" (in directory "E:\Projects\zgyt\drpapp\android\.."): CreateProcess error=2, 系统找不到指定的文
件。nnecting to Daemon
:ReactNative:Automatic import of native modules failed.

> Configure project :app
:ReactNative:Cannot run program "./node_modules/.bin/react-native" (in directory "E:\Projects\zgyt\drpapp\android\.."): CreateProcess error=2, 系统找不到指定的文
件。
:ReactNative:Automatic import of native modules failed.

> Task :app:installDebug
...

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@thymikee Running ./node_modules/.bin/react-native config from the root directory of the projects directly using Powershell gives the correct output.

I have currently changed my native_modules.gradle's getReactNativeConfig() to this and it works correctly:

ArrayList<HashMap<String, String>> getReactNativeConfig() {
    if (this.reactNativeModules != null) return this.reactNativeModules
    ArrayList<HashMap<String, String>> reactNativeModules = new ArrayList<HashMap<String, String>>()

    def cmdProcess
    def root = getReactNativeProjectRoot()
    def command = "powershell ./node_modules/.bin/react-native config"

    try {
      cmdProcess = Runtime.getRuntime().exec(command, null, root)
      cmdProcess.waitFor(5, java.util.concurrent.TimeUnit.SECONDS)
    } catch (Exception exception) {
      this.logger.warn("${LOG_PREFIX}${exception.message}")
      this.logger.warn("${LOG_PREFIX}Automatic import of native modules failed.")
      return reactNativeModules
    }

    def reactNativeConfigOutput = cmdProcess.in.text
    def json = new JsonSlurper().parseText(reactNativeConfigOutput)
    this.packageName = json["project"]["android"]["packageName"]
    def dependencies = json["dependencies"]

    dependencies.each { name, value ->
      def platformsConfig = value["platforms"];
      def androidConfig = platformsConfig["android"]

      if (androidConfig != null && androidConfig["sourceDir"] != null) {
        this.logger.info("${LOG_PREFIX}Automatically adding native module '${name}'")

        HashMap reactNativeModuleConfig = new HashMap<String, String>()
        reactNativeModuleConfig.put("name", name)
        reactNativeModuleConfig.put("nameCleansed", name.replaceAll('/', '_'))
        reactNativeModuleConfig.put("androidSourceDir", androidConfig["sourceDir"])
        reactNativeModuleConfig.put("packageInstance", androidConfig["packageInstance"])
        reactNativeModuleConfig.put("packageImportPath", androidConfig["packageImportPath"])
        this.logger.trace("${LOG_PREFIX}'${name}': ${reactNativeModuleConfig.toMapString()}")

        reactNativeModules.add(reactNativeModuleConfig)
      } else {
        this.logger.info("${LOG_PREFIX}Skipping native module '${name}'")
      }
    }

    return reactNativeModules
  }
}

@mi5ha
Copy link

mi5ha commented Jul 5, 2019

How are we supposed to create new RN project? When instructions on main RN site are followed, 2.0.1 of global CLI is installed and this error happens.

I also cant run mu RN app because of this (windows). It was running yesterday and just stopped.

@mi5ha

This comment has been minimized.

@thymikee

This comment has been minimized.

@mi5ha

This comment has been minimized.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

If it worked for you yesterday, then likely your environment is ok with running:

node ./node_modules/.bin/react-native config

(inside node_modules/@react-native-community/cli-platform-android/native_modules.gradle).

It baffles me how hard it is to get regular node scripts running in Windows. Since you guys are experienced in working with this environment, we expect some help and your expertise.

We could technically run this cross-platform using npx. However I'm not sure if it doesn't output anything else in some circumstances. For example we used to call this command with yarn if it was used in a project, but it turned out that with some versions of Yarn and some versions of Node it produced output that was breaking either Android or iOS scripts. It's not easy unfortunately.

@thymikee

This comment has been minimized.

@thecodrr

This comment has been minimized.

@mi5ha

This comment has been minimized.

@thecodrr

This comment has been minimized.

@zenz
Copy link

zenz commented Jul 5, 2019

@thymikee all right, then the new cli can pass the compile steps. but some error messages shown as previous commends said. like

:ReactNative:Cannot run program "./node_modules/.bin/react-native" (in directory "C:\Users\zenz\programs\test_app\android\.."): CreateProcess error=2, ϵͳҲָļ
:ReactNative:Automatic import of native modules failed.

> Configure project :app
:ReactNative:Cannot run program "./node_modules/.bin/react-native" (in directory "C:\Users\zenz\programs\test_app\android\.."): CreateProcess error=2, ϵͳҲָļ
:ReactNative:Automatic import of native modules failed.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

Seeing ./node_modules/.bin/react-native proves you're not on the latest version. The command is now node node_modules/react-native/cli.js config. Remove the entry in lock file and install again. Or remove the whole lock file and install again if you have issues.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

@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

@mi5ha
Copy link

mi5ha commented Jul 5, 2019

@theweavrs So instructions on official site are basically wrong?

I managed to make it work by:

  • Uninstalled global react-native-cli
  • Created new project with npx react-native init MyApp
  • Started JS server with npx react-native start
  • Run in android emulator with npx react-native run-android

And it worked! 🎉

@thecodrr

This comment has been minimized.

@mi5ha
Copy link

mi5ha commented Jul 5, 2019

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

@zenz

This comment has been minimized.

@thecodrr
Copy link
Contributor Author

thecodrr commented Jul 5, 2019

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

@mi5ha

This comment has been minimized.

@thymikee

This comment has been minimized.

@mi5ha

This comment has been minimized.

@thymikee

This comment has been minimized.

@mehranabi

This comment has been minimized.

@thecodrr

This comment has been minimized.

@mehranabi

This comment has been minimized.

@thecodrr

This comment has been minimized.

@thymikee
Copy link
Member

thymikee commented Jul 5, 2019

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.

@mehranabi
Copy link

@theweavrs , Oh yes, I missed that comment! Thanks
Got it @thymikee , Thank you for clearification!

@thecodrr

This comment has been minimized.

@thymikee

This comment has been minimized.

@Andersonfrfilho

This comment has been minimized.

@zenz

This comment has been minimized.

@Andersonfrfilho

This comment has been minimized.

@vishesh3006
Copy link

vishesh3006 commented Jul 6, 2019

@theweavrs So instructions on official site are basically wrong?

I managed to make it work by:

  • Uninstalled global react-native-cli
  • Created new project with npx react-native init MyApp
  • Started JS server with npx react-native start
  • Run in android emulator with npx react-native run-android

And it worked! 🎉

Thanks a lot. It worked

@xliank

This comment has been minimized.

@mescalito

This comment has been minimized.

@ldco2016
Copy link

anyone have experience getting this error on Azure DevOps? This is where we are continuing to get this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working env: windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.