该项目是全新的(使用create-react-app
创建),就像我在react
中一样。将与babel
和webpack
有关的所有帖子都涂成红色。安装,弹出它以及我发现的所有内容。错误是:
Error in ./components/MyInfo.js
Module parse failed: /var/www/html/react/myfirstapp/components/MyInfo.js Unexpected token (5:8)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (5:8)
@ ./src/index.js 13:14-45
如果MyInfo.js
与index.js
在同一文件夹中,则可以正常工作。将其移至components
文件夹后,发生错误。 MyInfo:
import React from "react"
function MyInfo() {
return (
<div>
<h1>Toma</h1>
<p>My name is Toma</p>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
)
}
export default MyInfo
Index.js:
import React from "react"
import ReactDOM from "react-dom"
import MyInfo from "../components/MyInfo"
ReactDOM.render(
<MyInfo />,
document.getElementById("root")
)