首页 > 解决方案 > React-native Hermes 生产构建失败

问题描述

react@17.0.1
react-native@0.63.4

没有 Hermes 的构建工作正常。

使用 Hermes 进行开发构建工作正常。

如果我注释掉所有代码并仅使用<Text>Works</Text>.

如果我放回所有依赖项:Redux、React-navigation、react-native-paper 等 - 构建过程会卡在 34%:

...
info Done writing bundle output
info Done writing sourcemap output
info Copying 32 asset files
info Done copying assets
/Users/main/git/my-app/app/android/app/build/generated/assets/react/release/index.android.bundle:13:134: warning: the variable "Promise" was not declared in function "isBoldTextEnabled"
...

其余日志遵循相同的模式:

the variable "SOMETHING" was not declared in function "SOMETHING"

react-native run-android --variant=release不会发出警告,但它与生产构建相同:

...
info Done copying assets
<=====--------> 41% EXECUTING [3m 20s]
> :app:bundleReleaseJsAndAssets

据我了解,这意味着问题是由我的 npm 依赖项之一引起的。有没有一种简单的方法可以解决这个问题,而无需手动逐个查看每个依赖项?

我已经解决了有关 StackOverflow 和 react-native Github 问题的所有相关问题。

标签: androidreact-nativereact-native-hermes

解决方案


我通过只用一个视图构建一个空的 APK,然后插入我的部分代码并一次又一次地构建,找到了根本原因。原来这个问题是由我的源代码中的一个大 JSON 文件引起的。

Hermes 有一个已知的错误。而不是加载.json文件,我必须加载一个字符串和JSON.parse()它。


推荐阅读