Cant deploy astro to vercel (node18, astro 5.3.0., vercel 8.0.7)

when i run “npx astro build” locally i get no problem, but when i deploy or make a commit to the repo, the vercel build process fails every single time. it doesn’t work. in return i get this message:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/dist/server/entry.mjs' imported from /opt/rust/nodejs.js

the message i will get on the frontend aims at a “serverless” function:

“This Serverless Function has crashed.”

iv’e made sure to install the vercel adapter and even detail where i want the build to go.

according to this blog (Error [ERR_MODULE_NOT_FOUND]: Cannot find module in JS | bobbyhadz) the error ocurs when i omit a file extension name, but since this happens on the build process on vercel, i don’t know what’s wrong with my config.

vercel.json

  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/static-build",
      "config": {
        "distDir": "dist"
      }
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "/"
    }
  ]
}

package.json

  "name": "mois",
  "type": "module",
  "version": "0.0.1",
  "scripts": {
    "astro": "astro",
    "dev": "astro dev",
    "start": "astro dev",
    "build": "astro build",
    "preview": "astro preview",
    "vercel-build": "astro build"
  },
  "dependencies": {
    "@astrojs/react": "^4.2.0",
    "@astrojs/vercel": "^8.0.7",
    "@portabletext/types": "^2.0.13",
    "@sanity/astro": "^3.1.11",
    "@sanity/client": "^6.27.2",
    "@sanity/color-input": "^4.0.3",
    "@sanity/image-url": "^1.1.0",
    "@sanity/locale-es-es": "^1.2.17",
    "@sanity/ui": "^2.14.0",
    "@sanity/vision": "^3.72.1",
    "@sanity/visual-editing": "^2.12.11",
    "@types/react": "^19.0.8",
    "@types/react-dom": "^19.0.3",
    "astro": "^5.3.0",
    "astro-portabletext": "^0.11.0",
    "groq": "^3.72.1",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "sanity": "^3.72.1",
    "sanity-plugin-asset-source-unsplash": "^3.0.3",
    "sass": "^1.84.0"
  },
  "devDependencies": {
    "rollup-plugin-visualizer": "^5.14.0",
    "vite": "^6.0.11"
  },
  "engines": {
    "node": "18.x"
  }
}

astro.config.mjs

import { loadEnv } from 'vite';
import { visualizer } from "rollup-plugin-visualizer";
import sanity from '@sanity/astro';
import react from '@astrojs/react';
import vercel from '@astrojs/vercel';

const env = loadEnv(import.meta.env.MODE, process.cwd(), '');

// https://astro.build/config
export default defineConfig({
  integrations: [
    sanity({
      projectId: env.PUBLIC_SANITY_PROJECT_ID,
      dataset: env.PUBLIC_SANITY_DATASET,
      useCdn: false,
      apiVersion: "2025-01-28",
      studioBasePath: "/studio",
      stega: {
        studioUrl: "/studio",
      },
    }),
    react(),
  ],
  output: 'server',
  adapter: vercel({
    analytics: true,
    webAnalytics: {
      enabled: true,
    },
    runtime: 'nodejs18.x',
    mode: 'serverless'
  }),
  vite: {
    plugins: import.meta.env.MODE === 'development' ? [visualizer({
      emitFile: true,
      filename: "stats.html",
    })] : [],
  }
});```

Hey,

Have you tried deploying Astro boilerplate template and see how it goes: Astro on Vercel ?

1 Like

hi, i have not and i will give it a go.

i created a minimal example here: GitHub - eduardonwa/noserverastro

if you can, try to deploy it let me know if the server folder gets made after running “npm run build”.

recently gave it another go on Vercel but got the same response as previously.

vercel url: https://gojira-psi.vercel.app/

I just deployed your project and unable to find any error: https://noserverastro.vercel.app/. Is there any specific steps you are doing to reproduce the error?

2 Likes

hi, thanks for taking the time!

here’s the exact order in which i tried to deploy the repo:

  1. create new astro project npm create astro@latest
  2. install vercel npm install @astrojs/vercel (and a few other type dependencies)
  3. configured the astro config:
output: "server",
adapter: vercel(),
  1. ensure node18 is specified in package.json
 "engines":
{ "node": "18" }
  1. create an api route for serverless functions by making “test.ts” within “src/pages/api/”
import { VercelRequest, VercelResponse } from "@vercel/node";

export default function handler(req: VercelRequest, res: VercelResponse) {
  throw new Error("Forcing an error in the serverless function");
}
  1. add this vercel.json
{
  "version": 2,
  "builds": [
    {
      "src": "api/**/*.ts",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/api/(.*)",
      "dest": "/api/$1"
    }
  ]
}
  1. run the build: npm run build

Those were the exact steps i took to create this repo.

  • the vercel npm install and the “other” type dependencies install: npm install @astrojs/vercel @vercel/node @types/node --save-dev

after the repo was finished i imported it to vercel.

Thanks! Before I try above, is there any specific usecase which isn’t fulfilled by our starter template: Astro on Vercel ?

2 Likes

well, not really, if the template has ssr and uses the latest version of astro, that’s something i can work with.

but since i already had started a project, if i knew it was going to be like this i would have started with a vercel template.

however, i do appreciate all the help you’ve given me though.

You should be able to use SSR with Astro Astro on Vercel

2 Likes

Hey so, by adding “imageService” into my astro config, it finally creates a server folder without warning messages. (the server folder was missing from my initial attempts)

  output: 'server',
  adapter: vercel({
    imageService: true,
    webAnalytics: {
      enabled: true,
    },
  }),

now it output a more satisfying response, locally:

09:46:51 [build] Rearranging server assets...
09:46:51 [@astrojs/vercel] Bundling function ../../../../dist/server/entry.mjs
09:46:53 [@astrojs/vercel] Copying static files to .vercel/output/static
09:46:53 [build] Server built in 23.94s
09:46:53 [build] Complete!

however when i push a new commit to github, and since i have linked my repo to vercel, i receive this message:

Error: Config file was not found at "/vercel/path0/.vercel/output/config.json"
at oP (/var/task/sandbox.js:675:115)
at async lYt (/var/task/sandbox.js:687:1917)
at async X3i (/var/task/sandbox.js:704:8024)
at async J3i (/var/task/sandbox.js:704:7825)

so, perhaps there is something wrong with my auto-deploy settings? or maybe the workflow is a bit different from what im aware of.

i could just unlink the repo and see what happens when running “vercel --prod” from my computer.

  • running the command “vercel” locally, pushes a successful new preview deployment to vercel
  • vercel won’t finish the deploy if i commit a new change directly to github
  • running vercel --prod locally will create a successful deploy to vercel

Have you tried using the automatic configuration? (You will have to remove manual config before running.)

npx astro add vercel

As described here:
https://docs.astro.build/en/guides/deploy/vercel/
And here:

(As well as the Vercel link that has already been shared…)

I did that a while back, and it worked for me.