gpt4 book ai didi

javascript - index.js 尝试导入错误 : './App' does not contain a default export (imported as 'App' )

转载 作者:行者123 更新时间:2023-11-28 16:47:47 26 4
gpt4 key购买 nike

我正在尝试使用 React 构建我的第一个应用程序来显示 React bootstrap,但从 ./src/index.js 返回错误。

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

有人可以帮忙吗?

这是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>
);
}

最佳答案

错误消息包含线索'./App'不包含默认导出(导入为'App')

解决方案是添加默认导出:

App.js

export default App;

关于javascript - index.js 尝试导入错误 : './App' does not contain a default export (imported as 'App' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60376423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com