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

React项目移动组件文件后出现Module not found导入异常问题排查

Fix: Module not found: Can't resolve '../App'

Let's break down what's causing this error and how to fix it:

Your project structure places App.js (or App.jsx) directly under the src/ directory, while your EditOrCreateUser.jsx lives in src/Components/CreateEditUser/.

The import line you’re currently using:

import { PropContext } from "../App";

only moves one level up from your component’s directory, landing you in src/Components/—but App.js isn’t located there, it’s one level higher in the root src/ folder.

The Immediate Fix

Update the import path to use two levels of relative navigation to reach the src/ directory:

import { PropContext } from "../../App";

../../ will take you from src/Components/CreateEditUser/ → src/Components/ → src/, where App.js is stored.

Why This Happened

Before you rearranged your component folders, the relative path to App.js was correct. Now that you’ve nested EditOrCreateUser one level deeper in the CreateEditUser subfolder, the path needs an extra ../ to reach the parent src/ directory.

Additional Troubleshooting (If the Fix Doesn’t Work Right Away)

  • Double-check filename accuracy: Ensure App.js (or App.jsx) matches the name in your import exactly—build tools like Webpack are case-sensitive, even on Windows systems.
  • Verify the context export: Confirm App.js properly exports PropContext with a line like export const PropContext = React.createContext(...).
  • Restart your dev server: Webpack’s cache can sometimes hold onto old path references, so a fresh restart will clear this up.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 15:59:07