React native IOS release build white screen: TypeError: n.render is not a function

React native IOS release build white screen: TypeError: n.render is not a function

在为 Release 构建我的 React native 项目时,它构建成功,但是当 运行 在设备或模拟器上时,屏幕保持白色并且 Xcode 上出现以下日志:

2018-10-08 10:28:57.199743+0200 ProjectName[24497:338417] 
libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not 
supported on this platform.
2018-10-08 10:28:57.329034+0200 ProjectName[24497:338417] [Crashlytics] 
Version 3.10.8 (131)
2018-10-08 10:28:57.696 [error][tid:com.facebook.react.JavaScript]         
TypeError: n.render is not a function. (In 'n.render()', 'n.render' is 
undefined)

This error is located at:
in i
2018-10-08 10:28:57.697854+0200 ProjectName[24497:338510] TypeError: 
n.render is not a function. (In 'n.render()', 'n.render' is undefined)

This error is located at:
in i
2018-10-08 10:28:57.699 [error][tid:com.facebook.react.JavaScript] 
TypeError: n.render is not a function. (In 'n.render()', 'n.render' is undefined)

This error is located at:
in i
 2018-10-08 10:28:57.699468+0200 ProjectName[24497:338510] TypeError: n.render is not a function. (In 'n.render()', 'n.render' is undefined)

This error is located at:
in i
2018-10-08 10:28:57.700 [fatal] 
[tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: 
TypeError: n.render is not a function. (In 'n.render()', 'n.render' is 
undefined)

This error is located at:
in i
2018-10-08 10:28:57.700153+0200 ProjectName[24497:338494] Unhandled JS 
Exception: TypeError: n.render is not a function. (In 'n.render()', 
'n.render' is undefined)

This error is located at:
in i
2018-10-08 10:28:57.715202+0200 ProjectName[24497:338494] *** 
Terminating app due to uncaught exception 'RCTFatalException: Unhandled 
JS Exception: TypeError: n.render is not a function. (In 'n.render()', 
 'n.render' is undefined)

This error is located at:
in i', reason: 'Unhandled JS Exception: TypeError: n.render is not a 
function. (In 'n.rende..., stack:
Jn@211:40538
Ur@211:56432
Ar@211:56864
si@211:61708
li@211:61128
ii@211:60256
Mr@211:59236
pi@211:66432
render@211:69043
exports@371:431
run@367:611
runApplication@367:2058
value@44:4050
<unknown>@44:889
value@44:3310
value@44:861
'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010dee929b 
__exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x000000010c124735 
objc_exception_throw + 48
    2   ProjectName                          0x000000010b333d62 
RCTFormatError + 0
    3   ProjectName                          0x000000010b330abc - 
[RCTExceptionsManager reportFatalException:stack:exceptionId:] + 507
    4   CoreFoundation                      0x000000010def011c 
__invoking___ + 140
    5   CoreFoundation                      0x000000010deed5b5 - 
[NSInvocation invoke] + 325
    6   CoreFoundation                      0x000000010deeda06 - 
[NSInvocation invokeWithTarget:] + 54
    7   ProjectName                          0x000000010b34738e - 
[RCTModuleMethod invokeWithBridge:module:arguments:] + 612
    8   ProjectName                          0x000000010b38d145 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 255
    9   ProjectName                          0x000000010b38cec3 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 78
    10  libdispatch.dylib                   0x000000011113d5d1 _dispatch_call_block_and_release + 12
    11  libdispatch.dylib                   0x000000011113e63e _dispatch_client_callout + 8
    12  libdispatch.dylib                   0x0000000111145b47 _dispatch_lane_serial_drain + 791
    13  libdispatch.dylib                   0x00000001111467c0 _dispatch_lane_invoke + 428
    14  libdispatch.dylib                   0x00000001111508b8 _dispatch_workloop_worker_thread + 733
    15  libsystem_pthread.dylib             0x000000011152d61c _pthread_wqthread + 409
    16  libsystem_pthread.dylib             0x000000011152d415 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这在通过 react-native run-ios --configuration Release 和通过 Xcode(使用发布配置)构建时都会发生。 调试工作正常。

项目使用 Typescript!

问题是 babel.config.js 而不是 .babelrc(Jest 需要 babel.config.js,但显然这会破坏发布版本)

我最终两者兼得,结合 babel 7 解决了我所有的问题。