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

使用Vite创建React项目时遭遇404页面未找到问题求助

Vite创建React项目后访问出现404错误

我尝试用Vite替代Create React App创建项目,但启动后访问页面出现404错误,操作步骤如下:

  • 在终端执行 npm create vite@latest client(选用React-JavaScript模板)
  • 执行 cd client
  • 执行 npm i
  • 执行 npm run dev

终端返回内容:

VITE v4.3.9  ready in 956 ms

  ➜  Local:   http://127.0.0.1:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help

但访问 http://127.0.0.1:5173/ 时出现404错误,提示页面未找到。

我已尝试以下解决方法:

  1. 在vite.config.js中配置其他端口:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
 server: {
    port: 3000,
  }
})
  1. 修改package.json中的scripts字段:
"scripts": {
    "dev": "vite --port 5173",
  },
  1. 尝试移动index.html到public和src目录。

初始项目结构:
初始项目结构截图

环境信息:React 18.2、Node 16.15.0、Vite 4.3.9,Create React App项目可正常运行,仅Vite项目出现该问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 01:17:04