Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

export default not working webpack, reactjs

I'm new to webpack, I'm starting to build an app using webpack and react 15, however it's like the export default is not working properly because I got an error as the App component is not found:

 5:9  App not found in './components/App'  import/named

Below the code of my index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import {Router,Route,IndexRoute,browserHistory} from 'react-router';
import { Provider } from 'react-redux';
import {App} from './components/App';
import {HomePage} from './components/HomePage';

import configureStore from './store/configureStore.js';
import { syncHistoryWithStore } from 'react-router-redux';



const store = configureStore();

const history = syncHistoryWithStore(browserHistory, store);
ReactDOM.render(
    <Provider store={store}>
        <Router history={history}>
            <Route path="/" component={App}>
                <IndexRoute component={HomePage}/>



            </Route>


        </Router>

    </Provider>,
    document.getElementById('app')
);

and the code of my App.js placed under components folder:

import React, { PropTypes } from 'react';


const App = (props) => {
  return (
    <div>
      {props.children}
    </div>
  );
};

App.propTypes = {
  children: PropTypes.element
};

export default App;

Can anyone see the problem? Looks like this type of export is not supported and I have to enable something? Any help is appreciatted!!

like image 414
fgonzalez Avatar asked Aug 20 '16 16:08

fgonzalez


People also ask

Why export default is not working?

The "export default was not found" error occurs when we try to import as default from a module that doesn't have a default export. To solve the error, make sure the module has a named export and wrap the import in curly braces, e.g. import {myFunction} from './myModule' .

Can't import the named export from default exporting module only default export is available?

Can't import the named Export children from non EcmaScript module only default export is available? Solution: You Just need to Downgrade the Framer motion version to “4.1. 17” in your package. json file and then run npm install Now, Your error must be solved.

What is difference between export default and export in react JS?

Exports without a default tag are Named exports. Exports with the default tag are Default exports. Using one over the other can have effects on your code readability, file structure, and component organization. Named and Default exports are not React-centric ideas.


1 Answers

Omit the curly braces:

import App from './components/App';

That's the trick with default, see.

like image 74
martriay Avatar answered Nov 06 '22 10:11

martriay