无法从另一个文件夹加载文件

时间:2019-08-27 20:15:54

标签: reactjs

该项目是全新的(使用create-react-app创建),就像我在react中一样。将与babelwebpack有关的所有帖子都涂成红色。安装,弹出它以及我发现的所有内容。错误是:

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.jsindex.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")
)

0 个答案:

没有答案