-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invariant Violation: Element type is invalid: expected a string( for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in. #16332
Comments
While this report is minimalistic (so I do understand nobody responded on this one), I do have the same error. I'm not on my workspace so I'll try to explain what happens. I was using version 0.43.x when I upgraded to 0.49.x. This was the moment my app failed because of dependencies (PropTypes, et cetera), so I tried to reinstall packages with NPM, clear cache, et cetera. The code does NOT recognize components by React Native. PHPStorm does not link the imported component (like it should do), so that seems to be related to this error when running At this moment I am planning to start a new project (newest version of RN) and copy my |
Any updates on this? |
I answer my own question. |
@simoarpe My editor gives me a warning when using |
@bobmulder supposedly it should be accurate, that is the same syntax used in the |
Okay I'll check it out when I'm home. Thanks for noticing! |
Adding my code
|
I am facing the same issue on Linux . |
I am facing this issue as well. I have tried solutions suggested by @dexter21r and @simoarpe but no luck. I am getting this error not in my root |
adding export default App worked for me export default App; AppRegistry.registerComponent('albums', () => App);` I was having the same in root App.js |
@rakeshgithub answer is work for me |
import React, { Component } from 'react'; export default class AddComponent extends Component{ |
Please what is the solution to this error? I have tried all the suggestions and no one worked for me. This is making react native really really unpredictable |
Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version? I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer. |
Hi smithaitufe, |
for me it was a difference between: import App from './app' and import App from './app/index.js' (the latter fixed the issue) |
i solve this problem by creating index.js file and exporting the file from it and at app.js import file from index.js . |
having the same problem today and I solved it just as prabin12 did. I created index.js in my components folder and export my app.js from it. import App from './App.js'; |
The next string version working as expected: export default class App extends React.Component { |
Tive esse problema quando tentei identar o return do render com o parentese na linha debaixo ex: |
I fixed this error after finding that i have been importing Image from native-base isntead of importing it from react-native. |
update** I got the same issue here. And tried various approaches, still not working. The most awkward thing is I import FormInputUI.js to another file use exactly same way as following and it works in that file. react-native: 0.55.0, FormInputUI.js
Main.js
|
@Sunnysh123 Hi did you check your package.json to update some libraries? cause my issue is the version conflict between different libraries and React Native. |
这 |
In my case it happened when I was importing List from react-native-elements to use it with FlatList. However, it seems react-native-elements no longer has List as a component since 1.0.0BETA4. Changing List to View fixed it for me. |
I solve it by change
to
|
import React, {Component} from 'react'; const GL = require("gl-react"); const shaders = GL.Shaders.create( uniform sampler2D img; const vec2 shadowCenter = vec2(0.5, 0.9); void main () { class HelloBlue extends React.Component export default class WebSearchScreen extends Component
} I am getting the same error in this class . please help me to solve this , I am not getting any link or solution of it. |
It's import problem. When I used: |
TL;DR It's not matter of react native. It's matter of javascript importing mechanism (esm, commonjs) I think it will help. 1. Synthetic importimport * as React from 'react'
// -> should import module with `* as`
import * as Module from 'third-party-module'
// In this case, it's also works.
// but it's not good to use `import` and `require` together
const Module = require('third-party-module') 2. Not synthetic importimport React from 'react'
// -> should import default
import Module from 'third-party-module' |
This solved it for me |
A slight variation that I'm including for any others that also hit it. For me, the this code was causing that same error.
(although bizarrely, if I changed the View to a Text it worked) The fix for me was to import from This works :
|
i have been having the same error, i tried all the above solutions and even went to just making a very simple app and discovered that the error only popped up when i was setting up my redux, when i added //// the problem might be due to the latest redux package but then again i m not to experienced in react-native to give a solid conclusion. please assist me further on my issue |
my mistake!!! i was importing my Provider from 'redux' instead from 'react-redux' once i fixed that issue the error stopped showing up after i fixed that the error stopped showing up! happy coding people! |
Removing the curly braces from the name of the function or the class, which I am importing solved the error for me. |
My reason of getting this error was that I've forgotten to add arguments section for function expression.
Instead of
Then |
I'm having the same issue, and it's the same react-native version. Renaming with "export default" or importing correctly is not the problem. Any news? If I update it, it should work? |
I get this issue as well. And I replace the TouchableOpacity import source 'from "native-base";' with 'from "react-native";'.it's work for me |
I narrowed down my error to navigationOptions.
how can i fix this?? |
in file index.js the first i wrote like that: |
Thanks. This helped me |
The same issue. I'm trying to pass redux store from first index.js to the next Components. The problem is when I'm passing the store to a simple Component, it's all right, but when I try to pass the store to decorated component, which is being exported like this: |
In my case it was a lack of attention, without realizing it was importing a class from a file that it did not exist. It was importing along with other classes from this same file, and only then did I realize that specifically this class was not from such a file. |
This isn't the most helpful error message. my issue was in the import import Provider from 'react-redux'; instead of import { Provider } from 'react-redux'; |
When you "export default" something then in your imports you can name it anything you want and you don't need to use curly braces around the import for example: Export: But if you are exporting the class A like this: Export: If you have a lot of exports from a single file e.g:
Then you can import them like:
I was getting this error when I was not putting curly braces around my imports when they were not being exported as default |
damn, @igorchru was right. It's all about attention. you see, i got same problem, turn out I was importing Card component from 'react-native' instead 'react-native-elements'. And my problem is solved. pay attention to your code guys, stay sharp |
some kind of whitespace that was not the standard white space was left by code I copied from the internet. I removed everything between component tags and it started working. |
Is this a bug report?
yes
App.js.txt
User_List.php.txt
Have you read the Contributing Guidelines?
(Write your answer here.)
Environment
Steps to Reproduce
(Write your steps here:)
Expected Behavior
(Write what you thought would happen.)
Actual Behavior
(Write what happened. Add screenshots!)
Reproducible Demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
The text was updated successfully, but these errors were encountered: