首页 > 解决方案 > 无法从其他文件夹加载文件

问题描述

该项目是全新的(创建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文件夹后发生错误。我的信息:

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

索引.js:

import React from "react"
import ReactDOM from "react-dom"

import MyInfo from "../components/MyInfo"

ReactDOM.render(
    <MyInfo />,
    document.getElementById("root")
)

标签: reactjs

解决方案


推荐阅读