Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import  createHistory  from 'history/createBrowserHistory';
import { Provider } from 'react-redux';
import  ConnectedRouter  from 'react-router-redux';
import { Route, Switch } from 'react-router';
import Home from "./pages/Home";
import Register from "./pages/Register";
import CourseManagerDashboard from "./pages/CourseManagerDashboard";
import CourseDetail from "./pages/CourseDetail";
import App from './app/App';
import LoginForm from './components/LoginForm';

const store = createStore(
    state => state
);
const history = createHistory();

ReactDOM.render((
    <Provider store={store}>
        <ConnectedRouter history={history}>
            <Switch>
                <Route name="home" exact path="/" component={Home} />
                <Route name="register" path="/register" component={Register} />
                <Route name="course-manager-dashboard" path="/course-manager-dashboard" component={CourseManagerDashboard} />
                <Route name="course-detail" path="/course-detail" component={CourseDetail} />
                <Route name="login" path="/login" component={LoginForm} />
                <Route path="/" component={App} />
            </Switch>
        </ConnectedRouter>
    </Provider>
),document.getElementById('app'));

Getting below error :

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, or you might have mixed up default and named imports. Unable to track where exactly the issue is.

like image 371
Rajendra Badri Avatar asked Jan 07 '19 13:01

Rajendra Badri


People also ask

Why are my imported components not showing up in my project?

You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Unable to track where exactly the issue is. I know this may sound silly, but try to check all your imported components with a simple console.log:

Why is my material-UI import not working?

You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Getting following error after migrating to material-ui 1.0

Why is my React Native import not working?

The React Native team has made this error more descriptive since the last version. Usually, mixed-up default and named imports are the culprits. It’s still tricky because, as you can see, the error is caused by a component that is imported into the app, but we can’t tell which one is imported improperly.


2 Answers

I know this may sound silly, but try to check all your imported components with a simple console.log:

console.log('Provider', Provider);
console.log('ConnectedRouter', ConnectedRouter);
console.log('Route', Route);
console.log('Switch', Switch);
console.log('Home', Home);
console.log('Register', Register);
console.log('CourseManagerDashboard', CourseManagerDashboard);
console.log('CourseDetail', CourseDetail);
console.log('App', App);
console.log('LoginForm', LoginForm);

Put this before ReactDOM.render, after const history = createHistory();

The line with undefined in it is causing the problem.

like image 91
Dávid Molnár Avatar answered Sep 17 '22 23:09

Dávid Molnár


In my case, the imports were correct. I just had to remove the braces around the imported class name in the imports section

It used to be

import {DropDownPicker} from 'react-native-dropdown-picker';

I just had to remove the braces around the DropDownPicker

like image 40
Harsha Avatar answered Sep 19 '22 23:09

Harsha