"react-native start" works, but crashes while "react-native run-android" is ongoing, even on a fresh project (bare workflow)

Viewed 2551

Running an app (created by "expo init appName" in Bare Workflow) on Android requires to first react-native start and then react-native run-android. What happens is -

  1. In 1st terminal, I run react-native start (tried from VS Code terminal, normal terminal, each of these as admin too). It works fine.

  2. In 2nd terminal, I run react-native run-android and the server crashes (in 1st terminal) and the 2nd terminal can either show error or show success.

In case of success, it's no use cause the server is not working so shows that error.

Unable to load script.Make sure you are either running a Metro server or that your bundle 'index.android.bundle' is packaged correctly for release.

In case of failure the error is (in the 2nd terminal, the one running react-native run-android)

> Task :app:createDebugExpoConfig FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8/userguide/command_line_interface.html#sec:command_line_warnings
30 actionable tasks: 2 executed, 28 up-to-date
internal/fs/utils.js:307
    throw err;
    ^

Error: ENOENT: no such file or directory, open 'D:\bareWorkflowRN\tester1PaymentsNPlacePicker\android\app\build\generated\assets\expo-constants\debug\app.config'
    at Object.openSync (fs.js:476:3)
    at Object.writeFileSync (fs.js:1467:35)
    at Object.<anonymous> (D:\bareWorkflowRN\tester1PaymentsNPlacePicker\node_modules\expo-constants\scripts\getAppConfig.js:20:4)  
    at Module._compile (internal/modules/cjs/loader.js:1063:30)   
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)        
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -4058,
  syscall: 'open',
  code: 'ENOENT',
  path: 'D:\\bareWorkflowRN\\tester1PaymentsNPlacePicker\\android\\app\\build\\generated\\assets\\expo-constants\\debug\\app.config'}

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:createDebugExpoConfig'.
> Process 'command 'cmd'' finished with non-zero exit value 1     

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 42s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
internal/fs/utils.js:307

and in the 1st terminal (react-native run)

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'D:\bareWorkflowRN\tester1PaymentsNPlacePicker\android\app\build\generated\assets\expo-constants'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (D:\bareWorkflowRN\tester1PaymentsNPlacePicker\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (fs.js:183:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'D:\\bareWorkflowRN\\tester1PaymentsNPlacePicker\\android\\app\\build\\generated\\assets\\expo-constants'

the part showing module-name "expo-constants" is NOT always the same. It varies at times, but the general structure of the error is this. for example

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'D:\bareWorkflowRN\tester1PaymentsNPlacePicker\node_modules\expo-error-recovery\android\build\kotlin\compileDebugKotlin\caches-jvm\jvm'  
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (D:\bareWorkflowRN\tester1PaymentsNPlacePicker\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (fs.js:183:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'D:\\bareWorkflowRN\\tester1PaymentsNPlacePicker\\node_modules\\expo-error-recovery\\android\\build\\kotlin\\compileDebugKotlin\\caches-jvm\\jvm'
}

I've tried (scouring the net, especially SO posts) -

a - delete node_modules and npm install

b - cd android and gradlew clean . No affect. I've tried this before react-native run and also in between the two mentioned commands.

I've tried these steps in various permutations for the last 2-3 days, but this is not solving.

I even thought that this might be due to the new expo version launch on 15th April, and maybe that's causing some versioning issues, so I tried with fresh projects made with expo init appName. No changes made to this fresh app, just tries to run it on the emulator. It works fine with expo start but if I try react-native start and react-native run-android, the same issues repeat.

One might note at this point, that the issue can be called cyclic in nature

Also, does it make sense to -

  • start the server react-native start
  • run react-native run-android, let the server crash and let the app install with error - "Unable to load script.Make sure you are either running a Metro server or that your bundle 'index.android.bundle' is packaged correctly for release."
  • then try react-native start again.

I think (don't know for sure) it doesn't make sense to start the server later, but out of my many efforts , this worked twice randomly. Could NOT be reproduced.

My system Windows 10 here's my package.json (it's the one generated with a fresh app and is untouched)

{
  "main": "index.js",
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "expo": "~41.0.0",
    "expo-splash-screen": "~0.10.2",
    "expo-status-bar": "~1.0.4",
    "expo-updates": "~0.5.4",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "~0.63.4",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-reanimated": "~2.1.0",
    "react-native-screens": "~3.0.0",
    "react-native-unimodules": "~0.13.3",
    "react-native-web": "~0.13.12"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0",
    "babel-jest": "~25.2.6",
    "jest": "~25.2.6",
    "react-test-renderer": "~16.13.1"
  },
  "jest": {
    "preset": "react-native"
  },
  "private": true
}

Any assist highly appreciated. Let me know if more information is needed

1 Answers

The same issue exists after expo 41 ejecting.

By looking on "no such file or directory... android\app\build\generated\assets\expo-constants\debug\app.config" output I workarounded by manual creating of the directory debug inside of the android\app\build\generated\assets\expo-constants.

And following yarn android succeded.

Note: in case of yarn android crash the debug directory should be recreated again.

P.S.: https://github.com/expo/expo-cli/blob/master/packages/config/src/Config.ts is being modified currently. So I hope this bug will be fixed soon.

Related