0
votes

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>
    );
}
3
try export default App at the bottom of your App.jsSquiggs.

3 Answers

3
votes

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;
1
votes

Use export dafault App; at last of App.js File

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>
    );
}
export dafault App;
0
votes

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;