Skip to content
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

Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. #9249

Closed
shibli786 opened this issue Mar 24, 2017 · 10 comments

Comments

@shibli786
Copy link

Do you want to request a feature or report a bug?
I think this is most probably is a Bug

index.js:946 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

How ever i have exported All component properly

// Forms.js

   import React from 'react'
   import ReactDOM from 'react-dom';
  export default class App extends React.Component{

      render(){
          return (
               <div>
             <ul>
	          <li>Home</li>
	     </ul>
                        {this.props.children}
              </div>
  	      );
      }
   }    


   export  class Home extends React.Component{

        render(){
         return (
               <div>
                     <h1>Home...</h1>
                 </div>
              )
       }
   }

//main.js

  import React from 'react';
  import ReactDOM from 'react-dom';
  import {App,Home} from './Forms.jsx';
  import {  Route, hashHistory } from 'react-router'
  import Router from 'react-router';

   ReactDOM.render((
       <Router history = {hashHistory}>
       <Route path = "/" component = {App}>
       <Route path = "/home" component = {Home} />
               </Route>
      </Router>
       ), document.getElementById('app'));




                "history": "^4.6.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^5.0.3",
"react-router": "^4.0.0",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.2"
@shibli786 shibli786 changed the title index.js:946 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Mar 24, 2017
@selbekk
Copy link
Contributor

selbekk commented Mar 24, 2017

It looks like you're importing your App component wrong. You're exporting it as default, but importing it as a named export.

To fix this, change the 3rd line of main.js to this:

import App, {Home} from './Forms.jsx';

, and that should work.

@gaearon
Copy link
Collaborator

gaearon commented Mar 24, 2017

Yep, that's the problem.

@gaearon gaearon closed this as completed Mar 24, 2017
@malikgenius
Copy link

Great ... took me 4 hours to find out and fixed in a second after landed here ...

@selbekk
Copy link
Contributor

selbekk commented Nov 9, 2017

@malikgenius - haha I feel you. This is one of those things that you spend a ton of time figuring out the first time, and then you know how to fix it forever.

A note though - React provides some really good error messages, so it helps to read them thoroughly.

@gaearon
Copy link
Collaborator

gaearon commented Nov 9, 2017

Yeah :-) the message pretty much says this:

You likely forgot to export your component from the file it's defined in.

@gaearon
Copy link
Collaborator

gaearon commented Nov 9, 2017

I guess we could amend and add something like "or you might have mistaken default and named imports".

@selbekk
Copy link
Contributor

selbekk commented Nov 9, 2017

On it @gaearon :)

@shardy315
Copy link

Hey @selbekk

In my App.js , I have the following code :

import React from 'react';
import { AppRegistry, View, Text } from 'react-native';

class App extends React.Component {
  render(){
    return (
      <View>
        <Text> Sierra </Text>
        <Text> Tanner </Text>
      </View>
    )
  }
}

AppRegistry.registerComponent('SampleApp', () => App);

This is very similar to https://facebook.github.io/react-native/docs/tutorial.html and I don't see what I am not sure what I am exporting/importing incorrectly .

Thank you :)

@selbekk
Copy link
Contributor

selbekk commented Dec 14, 2017

Can’t see anything wrong with that code tbh.

@gaearon
Copy link
Collaborator

gaearon commented Dec 14, 2017

I’ll lock this issue because any similar problems are not necessarily related to the particular problem this issue is describing, and closed issues don’t usually get responses. Please file a new issue if you experience a problem, along with a reproducing project.

@facebook facebook locked and limited conversation to collaborators Dec 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants