React Native error: Element type is invalid: expected a string or a class/function but got: object

后端 未结 9 729
不知归路
不知归路 2020-12-28 13:39

I am getting this error and I am having a lot of trouble fixing this.

What I am trying to do here is have 3 different screens and have a tabbar that navigates to eac

相关标签:
9条回答
  • 2020-12-28 13:51

    In my vase I was on react-native 0.46.4 and had something like import MainContainer from './app' where the app directory had a shared index.js file amongst Android and iOS, but React Native wasn't detecting an index.js inside app. Once I switched to import MainContainer from './app/index.js' it worked.

    0 讨论(0)
  • 2020-12-28 13:55

    Change your SwitchView definition to

    export default class SwitchView extends Component...

    0 讨论(0)
  • 2020-12-28 14:00

    This is probably caused by some JS module export/import issues in your program, typically for one of the two reasons listed below:

    • You forget to export, or you export something incorrectly
    • You import something that doesn't exist, or you import something incorrectly

    I ran into similar error, but in my case, it is not caused by export but caused by import, and I used the import statement incorrectly to import something that doesn't exist in the module.

    In my case, the import was incorrectly written as:

    import { MyComponent } from './MyComponents/MyComponent'

    while actually it should be:

    import MyComponent from './MyComponents/MyComponent'

    And it drove me crazy and took me a whole day to figure it out and I hope this will save several hours for some people.

    0 讨论(0)
  • 2020-12-28 14:05

    this error can be resolved by using Defualt

    instead of export use export default

    0 讨论(0)
  • 2020-12-28 14:06

    I faced this issue only for the packages installed. Previously I wrote as

    import WebView from 'react-native-webview-messaging/WebView';
    

    I changed to

    import { WebView } from 'react-native-webview-messaging/WebView';
    
    0 讨论(0)
  • 2020-12-28 14:08

    This error comes when you are trying to access a component which is not exported. In my case, I forgot to export a component and I was accessing it.

    0 讨论(0)
提交回复
热议问题