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",
})] : [],
}
});```