Skip to content

index.tsx breaks release build of example app #98

@bllanos

Description

@bllanos

Environment

Output of react-native info (probably not relevant):

System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
    Memory: 340.42 MB / 15.34 GB
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 10.19.0 - /usr/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 14.0.1 - /usr/bin/javac
    Python: 2.7.18 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.2 => 0.62.2 
  npmGlobalPackages:
    *react-native*: Not Found

Description

The example Android app builds in debug mode, but not in release mode. I get the following error when running yarn example android --variant=release:

yarn run v1.22.4
$ yarn --cwd example android --variant=release
$ react-native run-android --variant=release
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 958 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...

> Task :app:bundleReleaseJsAndAssets FAILED
warning: the transform cache was reset.
Error: The resource `PROJECT_ROOT/example/index.js` was not found.
    at fs.realpath.err (PROJECT_ROOT/example/node_modules/metro/src/IncrementalBundler.js:157:26)
    at gotStat (fs.js:1600:21)
    at FSReqWrap.oncomplete (fs.js:153:21)

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.5/userguide/command_line_interface.html#sec:command_line_warnings
5 actionable tasks: 2 executed, 3 up-to-date
error The resource `PROJECT_ROOT/example/index.js` was not found. Run CLI with --verbose flag for more details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'npx'' 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 6s

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 app:installRelease -PreactNativeDevServerPort=8081
error The resource `PROJECT_ROOT/example/index.js` was not found. Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Workaround/Solution

Rename example/index.tsx to example/index.js.

The reasoning behind this is that, "You should leave the ./index.js entrypoint file as it is otherwise you may run into an issue when it comes to bundling a production build." (https://reactnative.dev/docs/typescript)

Reproducible Demo

  1. Run npx @react-native-community/bob create react-native-awesome-module and enter the following choices:
? What is the name of the npm package? react-native-awesome-module
? What is the description for the package? Description
? What is the name of package author? Name
? What is the email address for the package author? [email protected]
? What is the URL for the package author? https://www.github.com/author
? What is the URL for the repository? https://www.github.com/author/repository
? What type of package do you want to develop? JavaScript module with native example
  1. cd react-native-awesome-module/
  2. Fix Android build fails #65
  3. Run yarn bootstrap
  4. Run yarn example android --variant=release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions