javascript – index.js attempted import error: './App' does not contain a default export (imported as 'App')-ThrowExceptions

Exception or error:

I am trying to build my first app with React to display React bootstrap but returns errors from ./src/index.js.

Attempted import error: ‘./App’ does not contain a default export (imported as ‘App’).

Can anyone help please?

This is the index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import { Card } from "react-bootstrap";
import { Button } from "react-bootstrap";

ReactDOM.render(<App />, document.getElementById('root'));

const Example = (props) => {
    return (
        <Card style={ { width: "18rem" } }>
            <Card.Img variant="top" src="holder.js/100px180" />
            <Card.Body>
                <Card.Title>Card Title</Card.Title>
                <Card.Text>
                    Some quick example text to build on the card
                    title and make up the bulk of
                    the card's content.
                </Card.Text>
                <Button variant="primary">Go somewhere</Button>
            </Card.Body>
        </Card>
    );
};

export default Index;

serviceWorker.unregister();
import React from 'react';
import './App.css';
import "bootstrap/dist/css/bootstrap.min.css";
import { Card } from "react-bootstrap";
import { Button } from "react-bootstrap";

function App() {
    return (
        <Card style={ { width: "18rem" } }>
            <Card.Img variant="top" src="holder.js/100px180" />
            <Card.Body>
                <Card.Title>Card Title</Card.Title>
                <Card.Text>
                    Some quick example text to build on the card
                    title and make up the bulk of
                    the card 's content.
                </Card.Text>
                <Button variant="primary">Go somewhere</Button>
            </Card.Body>
        </Card>
    );
}
How to solve:

The error message holds the clue './App' does not contain a default export (imported as 'App')

The solution is to add a default export:

App.js

export default App;

###

Please add an export in your App component in the end


    import React from 'react';
    import logo from './logo.svg';
    import './App.css';
    import "bootstrap/dist/css/bootstrap.min.css";
    import {
      Card
    } from "react-bootstrap";
    import {
      Button
    } from "react-bootstrap";

    function App() {
      return ( <Card style = {
          {
            width: "18rem"
          }
        } >
        <Card.Img variant = "top"
        src = "holder.js/100px180"/>
        <Card.Body >
        <Card.Title > Card Title < /Card.Title> <Card.Text >
        Some quick example text to build on the card title and make up the bulk of
        the card 's content. </Card.Text> <Button variant = "primary" > Go somewhere < /Button> <
      /Card.Body>`` </Card>
      );
    }

   export default App;

Leave a Reply

Your email address will not be published. Required fields are marked *