You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目Module not found错误求助:导入路径问题排查

解决React中Module not found导入路径错误

以下是针对你遇到的三个导入路径错误的具体修正方案:

1. Home.js 导入Cards1.js的路径错误

错误根源:Home.js位于src/Components/Pages1,而Cards1.js在src/Components/Cards目录下,你当前的导入路径是在Pages1子目录里找Components,实际不存在这个层级。

修正后的Home.js代码:

import React from 'react'
import HeroSection from '../HeroSection'
// 调整路径:从Pages1回到Components目录,再进入Cards文件夹
import Cards1 from '../Cards/Cards1.js';

function Home(){
    return(
        <>
        <HeroSection> </HeroSection>
        <Cards1 />
        </>
    )
}

export default Home

2. ScheduleAppointment.js 导入SForm.js的路径错误

错误根源:ScheduleAppointment.js在src/Components/Pages1,SForm.js和Pages1同级(都在src/Components下),你当前的路径错误地在Pages1里找Components子目录。

修正后的ScheduleAppointment.js代码:

import React from "react";
// 调整路径:从Pages1回到Components目录,直接导入SForm
import SForm from '../SForm.js'

function ScheduleAppointment(){
    return(
        <SForm></SForm>
    )
}

export default ScheduleAppointment

3. Services.js 导入App.css的路径错误

错误根源:Services.js在src/Components/Pages1,App.css在src根目录,需要向上两级目录才能定位到。

修正后的Services.js代码:

import React from "react";
// 调整路径:从Pages1回到Components,再回到src根目录导入App.css
import '../../App.css'

function Services(){
    return(
        <>
        
        </>
    )
}

export default Services

小提示

React中导入路径的./代表当前文件所在目录,../代表上一级目录,多层嵌套时需要根据实际目录层级逐步调整路径,建议核对文件结构时可以逐层确认目录关系。

内容的提问来源于stack exchange,提问作者Madysan Miller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 21:57:09