安卓打包后,安装运行闪崩,报错"withRef is removed...."



  • 这个该怎么破,网上查了很多关于withRef is removed. To access the wrapped instance, use a ref on the connected component,都解决不了。追踪错误信息如下,

    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: com.facebook.react.common.JavascriptException: withRef is removed. To access the wrapped instance, use a ref on the connected component, stack:
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: default@951:770
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: <unknown>@956:1197
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: a@942:554
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: <unknown>@651:1194
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: d@2:768
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: n@2:409
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: t@2:262
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: <unknown>@305:141
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: d@2:768
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: n@2:409
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: t@2:262
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: <unknown>@12:42
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: d@2:768
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: n@2:339
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: t@2:262
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: global code@1077:8
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at java.lang.reflect.Method.invoke(Native Method)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at android.os.Handler.handleCallback(Handler.java:883)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at android.os.Handler.dispatchMessage(Handler.java:100)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at android.os.Looper.loop(Looper.java:224)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
    02-05 16:19:05.493  3836  3873 E TaroDemoCrashHandler: 	at java.lang.Thread.run(Thread.java:919)
    


  • 对了,忘了说,这个taro项目采用了dva,参照网上的说法应该是connect这里的问题:

    import { connect } from "@tarojs/redux";
    @connect(({ demo }) => ({
      ...demo
    }))
    class Demo extends Component<DemoProps, DemoState> {
    }
    


  • com.facebook.react.common.JavascriptException:
    这个错误是 React 报的。

    参考一下这个:https://stackoverflow.com/questions/53819335/withref-is-removed-to-access-the-wrapped-instance-use-a-ref-on-the-connected-c/53819524

    可能是 react-redux 版本太高导致的。



  • @蜘蛛paipai react-redux降级了到了5.x,编译的bundle中还是有withRef,安装运行还是同样的问题。



  • 为了方便,我把重现代码放到了码云上,https://gitee.com/andyge/simple_taro_demo ,这个是测试端,里面用了dva,壳子的话就用 git clone git@github.com:NervJS/taro-native-shell.git获取吧。


登录后回复