NodeJS React Module Not Found Error:Upgraded to Latest react-dom,重新设置文件路径,清除缓存,仍面临问题

cyvaqqii  于 12个月前  发布在  Node.js
关注(0)|答案(1)|浏览(110)

我是react的新手,我遇到了这个问题,我试图在AllMeetups.js组件中导入MeetupList.js组件,但我已经导出了MeetupList组件。
我的文件结构是这样的

src
|-- components
|   |-- meetups
|   |   |-- MeetupList.js
|   |   |-- MeetupItem.js
|-- pages
|   |-- AllMeetups.js

字符串
这是我在AllMeetups.js文件中的导入
“从'../components/meetups/MeetupList.js'导入MeetupList“
这是我在浏览器中得到的错误.编译与问题:ERROR in ./src/components/pages/AllMeetups.js 4:0-61模块未找到:Error:无法解析“../components/meetups/MeetupList.js”in“/home/zoren/my-react-app/src/components/pages”
AllMeetup.js

import MeetupList from "../components/meetups/MeetupList";
import classes from "./AllMeetups.module.css";

const DUMMY_DATA = [
  {
    id: "m1",
    title: "This is a first meetup",
    image:
      "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Stadtbild_M%C3%BCnchen.jpg/2560px-Stadtbild_M%C3%BCnchen.jpg",
    address: "Meetup street 5, 12345 Meetup City",
    description:
      "This is a first, amazing meetup which you definitely should not miss. It will be a lot of fun!",
  },
  {
    id: "m2",
    title: "This is a second meetup",
    image:
      "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Stadtbild_M%C3%BCnchen.jpg/2560px-Stadtbild_M%C3%BCnchen.jpg",
    address: "Meetup street 5, 12345 Meetup City",
    description:
      "This is a first, amazing meetup which you definitely should not miss. It will be a lot of fun!",
  },
];

function AllMeetupsPage() {
  return (
    <section className={classes.header}>
      <h1> All Meetups</h1>
      <MeetupList meetups= {DUMMY_DATA} />
    </section>
  );
}

export default AllMeetupsPage;


MeetupList.js

import MeetupItem from "./meetups/MeetupItem";
import classes from "./MeetupList.module.css";

function MeetupList(props) {
  return (
    <ul className={classes.list}>
      {props.meetups.map((meetup) => (
        <MeetupItem
          key={meetup.id}
          id={meetup.id}
          image={meetup.image}
          title={meetup.title}
          address={meetup.address}
          description={meetup.description}
        />
      ))}
    </ul>
  );
}

export default MeetupList;


MeetupItem.js

import classes from "./MeetupItem.module.css";

function MeetupItem(props) {
  return (
    <li className={classes.item}>
      <div className={classes.image}>
        <img src={props.img} alt={props.title} />
      </div>
      <div className={classes.content}>
        <h3> TITLE</h3>
        <address>{props.title}</address>
        <p> {props.description}</p>
      </div>
      <div className={classes.actions}>
        <button> To Favorites </button>
      </div>
    </li>
  );
}
export default MeetupItem;


这些都是我已经尝试过的东西。更新权限:

  • 将react-dom和NPM更新到最新版本。
  • 验证路径:
  • 已确认正确的文件路径。
  • 重新创建文件:
  • 重新创建并使用相同名称重新创建文件。
  • 重新启动服务器:
  • 已重新启动开发服务器。
  • 检查Typos:
  • 已确保导入语句中没有拼写错误或语法错误。
  • 清除缓存:
  • 已清除npm缓存。
  • 学历:
  • 已删除node_modules并重新安装依赖项。
  • 附加检查:
  • 确保没有循环依赖,验证Node.js和NPM版本,并审查package.json的正确性。
5ssjco0h

5ssjco0h1#

相对于components/pages中的文件的路径必须是../../components/meetup/MeetupList./meetup/MeetupList,因为..本身就是组件目录,所以现在的../components将是components/components,这显然不存在。

相关问题