You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

React项目无法运行:[plugin:vite:import-analysis]导入路径解析失败问题求助

Fixing Vite Import Resolution Error in React Project

Hey there, let's get your React project up and running again! The error you're hitting is a common relative path mix-up—super straightforward to fix once we break it down.

What's causing the issue?

Your App.jsx file lives directly inside the src folder. When you use ./src/assets/Header.jsx as the import path, Vite tries to look for a src folder inside your existing src directory (so it's checking src/src/assets/Header.jsx), which doesn't exist. That's exactly why you're seeing the "无法从'src/App.jsx'解析导入'./src/assets/Header.jsx'" error.

How to fix it

Just tweak the relative paths in your App.jsx to remove the extra ./src prefix. Since assets is a subfolder of src (same parent level as App.jsx), you can reference it directly:

// Original (incorrect) imports:
import Header from "./src/assets/Header.jsx";
import Footer from "./src/assets/Footer.jsx";

// Corrected imports:
import Header from "./assets/Header.jsx";
import Footer from "./assets/Footer.jsx";

Quick sanity checks

  • Confirm your file structure matches: you should have src/assets/Header.jsx and src/assets/Footer.jsx exactly (keep an eye on capitalization—even on Windows, Vite treats filenames as case-sensitive).
  • Double-check that the files haven't been moved or renamed by accident.

Once you update those import lines, restart your Vite dev server, and your project should run like it did before!

内容的提问来源于stack exchange,提问作者M A Aziz Umair

火山引擎 最新活动