react-native: Cannot add a child that doesn't have a YogaNode to a parent without a measure function! (Trying to add a 'ReactVirtualTextShadowNode' to a 'NativeViewWrapper')
I add code below to use yoga-node,but got an error,what‘s wrong?
@Override
protected UIImplementationProvider getUIImplementationProvider() {
return new FlatUIImplementationProvider();
}
"react-native": "0.43.3"
java.lang.RuntimeException: Cannot add a child that doesn't have a YogaNode to a parent without a measure function! (Trying to add a 'ReactVirtualTextShadowNode' to a 'NativeViewWrapper')
at com.facebook.react.uimanager.ReactShadowNode.addChildAt(ReactShadowNode.java:173)
at com.facebook.react.flat.FlatShadowNode.addChildAt(FlatShadowNode.java:217)
at com.facebook.react.flat.NativeViewWrapper.addChildAt(NativeViewWrapper.java:98)
at com.facebook.react.flat.FlatUIImplementation.addChildAt(FlatUIImplementation.java:510)
at com.facebook.react.flat.FlatUIImplementation.setChildren(FlatUIImplementation.java:190)
at com.facebook.react.uimanager.UIManagerModule.setChildren(UIManagerModule.java:326)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:345)
at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:141)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (2 by maintainers)
This happens if you have space like mentioned above, or if you have conditional rendering, that is checking a non boolean variable, that can be undefined or an empty string. Example:
This returns an error if
myCheck
isundefined
, or an empty string, because if its a falsy value, it’s going to be the value returned in the expression, and so, React will try to render it, but React cannot render undefined or empty string values inside non-Text
elements, throwing the error above.The solution is to cast the variable to a boolean:
Since false is correctly ignored on JSX.
This seems to be a problem with something that parses what your component returns from render().
in my case i had the following code:
and the fix was removing the semicolon:
this is still happening on 0.50.4
This error should be reformated. I just made a simple JSX mistake but took forever to find it.
I wasted more than a day on this and found no useful solution anywhere.
I got this error because I had put a comment inside a component.
On removing that comment the app did run for me.
i used to have the same issue , the solution is : don’t make spaces in declaration of components for example look at Text tag ( there’s space between > and Text ) <Text >this a compenent </Text> make it like that :<Text >this a compenent </Text>