![](/img/trans.png)
[英]./src/index.js Attempted import error: './App.js' does not contain a default export (imported as 'App')
[英]index.js attempted import error: './App' does not contain a default export (imported as 'App')
我正在尝试使用 React 构建我的第一个应用程序以显示 React 引导程序,但从./src/index.js
返回错误。
尝试导入错误:“./App”不包含默认导出(作为“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' does not contain a default export (imported as 'App')
解决方案是添加一个默认导出:
应用程序.js
export default App;
使用export dafault App; 最后的 App.js 文件
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;
最后请在您的 App 组件中添加导出
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.