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

SolidJS SSR项目部署到Vercel后出现404: not found错误求助

SolidJS SSR项目部署到Vercel后出现404: not found错误求助

Hey Harry, sorry to hear you're stuck with this 404 issue after deploying your SolidJS SSR project to Vercel—let's go through some common troubleshooting steps that should help you fix this:

  • 确认构建输出目录的正确性
    先在本地执行你的构建命令(比如npm run build、pnpm build或者yarn build),然后检查项目根目录下的dist文件夹是否生成了完整的SSR产物。打开dist看看有没有客户端资源文件夹(比如client)和服务器端入口文件(比如server.js)。另外,去你的项目配置文件(vite.config.ts或solid-start.config.ts)里确认build.outDir是否确实设置为dist,有些SolidJS模板默认的输出目录可能不是这个,需要手动配置。

  • 检查Vercel的构建命令是否匹配
    你提到只修改了输出目录,但Vercel默认的构建命令可能不适合SolidJS SSR项目。比如如果用的是Solid Start框架,构建命令应该是npm run build;如果是自定义Vite SSR,也要确保命令能正确触发完整的SSR构建。去Vercel的Build & Development Settings里确认Build Command字段是不是你本地用的那个构建命令,别用错成npm run dev之类的开发命令了。

  • 查看Vercel的部署日志找问题
    去Vercel的部署详情页面,翻一下Build阶段的日志,看看有没有报错信息。比如有没有提示“dist directory not found”、依赖安装失败,或者构建过程中出现编译错误?如果构建没成功完成,Vercel可能没有拿到正确的dist产物,自然会返回404。日志里的错误信息是定位问题的关键。

  • 确保SolidJS项目适配Vercel的SSR环境
    如果是用Solid Start开发的,你需要安装并配置Vercel适配器:

    // solid-start.config.ts
    import { defineConfig } from "solid-start/config";
    import vercel from "@solidjs/vercel";
    
    export default defineConfig({
      adapter: vercel(),
    });
    

    这个适配器会帮你自动配置Vercel所需的服务器端函数和路由规则。如果是自定义的Vite SSR项目,你需要在Vercel里指定服务器入口,或者创建vercel.json来配置路由重写,让所有请求都指向你的SSR服务端文件,比如:

    {
      "rewrites": [{ "source": "/(.*)", "destination": "/server.js" }]
    }
    

    记得把server.js替换成你实际的服务器入口文件名。

  • 验证本地SSR的路由是否正常
    先在本地启动SSR服务(比如npm run start),测试所有页面是否能正常访问。如果本地就有某些页面404,那问题可能出在项目的路由配置上,得先修复本地的路由问题再重新部署。

Try working through these steps one by one—more often than not, one of these fixes will get your site up and running on Vercel smoothly. If you spot any specific errors in the logs or config files that you're confused about, feel free to share more details and we can dig deeper!

备注:内容来源于stack exchange,提问作者Harry Albert

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.22 11:58:04