Build RBuild runs Locally Fine but on Vercel says Error

Able to run this build locally fine but on Vercel it says:

[12:28:25.688] Running build in Washington, D.C., USA (East) – iad1
[12:28:25.689] Build machine configuration: 2 cores, 8 GB
[12:28:25.702] Cloning github.com/Sid-AutoWisdom/autowisdom-frontend (Branch: ft/dashboard, Commit: 9acf76e)
[12:28:26.776] Cloning completed: 1.074s
[12:28:29.260] Restored build cache from previous deployment (3Zrh8Hz4p1BQLHGoirUEaptufJfN)
[12:28:31.060] Running "vercel build"
[12:28:32.087] Vercel CLI 44.5.0
[12:28:32.441] Installing dependencies...
[12:28:34.591] 
[12:28:34.592] up to date in 2s
[12:28:34.592] 
[12:28:34.592] 249 packages are looking for funding
[12:28:34.593]   run `npm fund` for details
[12:28:34.621] Detected Next.js version: 15.4.4
[12:28:34.628] Running "npm run build"
[12:28:34.742] 
[12:28:34.743] > autowisdom-frontend@0.1.0 build
[12:28:34.743] > next build
[12:28:34.744] 
[12:28:35.922]    β–² Next.js 15.4.4
[12:28:35.924]    - Experiments (use with caution):
[12:28:35.924]      βœ“ optimizeCss
[12:28:35.924] 
[12:28:35.964]    Creating an optimized production build ...
[12:29:12.130]  βœ“ Compiled successfully in 36.0s
[12:29:12.137]    Linting and checking validity of types ...
[12:29:33.440]    Collecting page data ...
[12:29:37.395]    Generating static pages (0/27) ...
[12:29:38.761]    Generating static pages (6/27) 
[12:29:39.120]    Generating static pages (13/27) 
[12:29:39.273]    Generating static pages (20/27) 
[12:29:39.368]  βœ“ Generating static pages (27/27)
[12:29:39.738]    Finalizing page optimization ...
[12:29:39.742]    Collecting build traces ...
[12:29:47.792] 
[12:29:47.803] Route (app)                                       Size  First Load JS
[12:29:47.804] β”Œ β—‹ /                                          9.19 kB         160 kB
[12:29:47.804] β”œ β—‹ /_not-found                                1.02 kB         104 kB
[12:29:47.804] β”œ β—‹ /about                                     5.42 kB         162 kB
[12:29:47.804] β”œ β—‹ /adminpage                                 4.85 kB         149 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/articles                 6.18 kB         183 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/articles/create          1.78 kB         377 kB
[12:29:47.805] β”œ Ζ’ /adminpage/manage/articles/edit/[id]       1.42 kB         376 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/consultancy              21.5 kB         254 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/coupons                  9.03 kB         174 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/questionnaire            11.4 kB         171 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/questionnaire/responses  7.24 kB         182 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/recommended-products     9.16 kB         178 kB
[12:29:47.805] β”œ β—‹ /adminpage/manage/users                     8.7 kB         197 kB
[12:29:47.805] β”œ Ζ’ /api/revalidate                              172 B         103 kB
[12:29:47.805] β”œ β—‹ /articles                                  9.86 kB         190 kB
[12:29:47.806] β”œ Ζ’ /articles/[slug]                           8.33 kB         172 kB
[12:29:47.806] β”œ Ζ’ /cars                                      6.33 kB         187 kB
[12:29:47.806] β”œ Ζ’ /cars/[id]                                 9.67 kB         214 kB
[12:29:47.806] β”œ β—‹ /consultancy                                 20 kB         250 kB
[12:29:47.806] β”œ β—‹ /consultation                                571 B         103 kB
[12:29:47.806] β”œ β—‹ /login                                     4.89 kB         158 kB
[12:29:47.806] β”œ β—‹ /newsletter/confirm                        3.88 kB         175 kB
[12:29:47.806] β”œ β—‹ /newsletter/unsubscribe                    3.56 kB         171 kB
[12:29:47.806] β”œ β—‹ /post-consultation-questionnaire           1.29 kB         218 kB
[12:29:47.806] β”œ β—‹ /pre-consultation-questionnaire            1.36 kB         218 kB
[12:29:47.806] β”œ β—‹ /privacy-policy                            4.73 kB         156 kB
[12:29:47.806] β”œ β—‹ /recommended-products                      5.75 kB         213 kB
[12:29:47.806] β”œ β—‹ /robots.txt                                  172 B         103 kB
[12:29:47.806] β”” Ζ’ /sitemap.xml                                 172 B         103 kB
[12:29:47.806] + First Load JS shared by all                   103 kB
[12:29:47.806]   β”œ chunks/6711-af4a09443f88132c.js            12.8 kB
[12:29:47.807]   β”œ chunks/9248-41a400e29f5295a5.js            54.1 kB
[12:29:47.807]   β”” chunks/9433-6d52264cff20e68a.js              16 kB
[12:29:47.807]   β”” other shared chunks (total)                19.6 kB
[12:29:47.807] 
[12:29:47.807] 
[12:29:47.807] Ζ’ Middleware                                   34.6 kB
[12:29:47.807] 
[12:29:47.807] β—‹  (Static)   prerendered as static content
[12:29:47.807] Ζ’  (Dynamic)  server-rendered on demand
[12:29:47.807] 
[12:29:48.026] Traced Next.js server files in: 84.221ms
[12:29:48.351] Created all serverless functions in: 324.984ms
[12:29:48.360] Error: Unable to find lambda for route: /adminpage/manage/consultancy
[12:29:48.947] 
[12:29:51.485] Exiting build container

package.json:

{
  "name": "autowisdom-frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@heroui/framer-utils": "^2.1.19",
    "@radix-ui/react-accordion": "^1.2.3",
    "@radix-ui/react-checkbox": "^1.3.2",
    "@radix-ui/react-dialog": "^1.1.6",
    "@radix-ui/react-dropdown-menu": "^2.1.6",
    "@radix-ui/react-label": "^2.1.2",
    "@radix-ui/react-popover": "^1.1.6",
    "@radix-ui/react-progress": "^1.1.2",
    "@radix-ui/react-radio-group": "^1.3.7",
    "@radix-ui/react-scroll-area": "^1.2.3",
    "@radix-ui/react-select": "^2.1.6",
    "@radix-ui/react-separator": "^1.1.2",
    "@radix-ui/react-slider": "^1.2.3",
    "@radix-ui/react-slot": "^1.2.0",
    "@radix-ui/react-switch": "^1.2.5",
    "@radix-ui/react-tabs": "^1.1.3",
    "@radix-ui/react-toast": "^1.2.6",
    "@radix-ui/react-tooltip": "^1.1.8",
    "@tiptap/core": "^2.11.7",
    "@tiptap/extension-character-count": "^2.11.7",
    "@tiptap/extension-color": "^2.11.7",
    "@tiptap/extension-font-family": "^2.11.7",
    "@tiptap/extension-image": "^2.11.7",
    "@tiptap/extension-link": "^2.11.7",
    "@tiptap/extension-table": "^2.11.7",
    "@tiptap/extension-table-cell": "^2.11.7",
    "@tiptap/extension-table-header": "^2.11.7",
    "@tiptap/extension-table-row": "^2.11.7",
    "@tiptap/extension-text-align": "^2.11.7",
    "@tiptap/extension-text-style": "^2.11.7",
    "@tiptap/extension-underline": "^2.11.7",
    "@tiptap/pm": "^2.11.7",
    "@tiptap/react": "^2.11.7",
    "@tiptap/starter-kit": "^2.11.7",
    "@typescript-eslint/eslint-plugin": "^8.35.0",
    "@typescript-eslint/parser": "^8.35.0",
    "axios": "^1.8.4",
    "chart.js": "^4.4.8",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "critters": "^0.0.23",
    "date-fns": "^4.1.0",
    "form-data": "^4.0.4",
    "framer-animations": "^1.5.15",
    "framer-motion": "^12.6.3",
    "framer-motion-hooks": "^1.0.10",
    "glob": "^10.4.5",
    "gsap": "^3.12.7",
    "isomorphic-dompurify": "^2.22.0",
    "lefthook": "^1.11.6",
    "lucide-react": "^0.487.0",
    "minimatch": "^10.0.3",
    "next": "^15.4.4",
    "next-themes": "^0.4.6",
    "on-headers": "^1.1.0",
    "react": "^19.1.0",
    "react-chartjs-2": "^5.3.0",
    "react-colorful": "^5.6.1",
    "react-day-picker": "^8.10.1",
    "react-dom": "^19.1.0",
    "react-hook-form": "^7.55.0",
    "react-hot-toast": "^2.5.2",
    "react-icons": "^5.5.0",
    "react-intersection-observer": "^9.16.0",
    "react-select": "^5.10.1",
    "recharts": "^2.15.2",
    "sitemap": "^8.0.0",
    "spring-easing": "^2.3.3",
    "tailwind-merge": "^3.1.0",
    "tailwind-scrollbar": "^2.1.0",
    "tailwindcss-animate": "^1.0.7",
    "zustand": "^5.0.3"
  },
  "devDependencies": {
    "@evilmartians/lefthook": "^1.11.6",
    "@types/node": "^22.14.0",
    "@types/react": "^19.1.0",
    "@types/react-dom": "^19.1.1",
    "autoprefixer": "^10.4.14",
    "dompurify": "^3.2.5",
    "eslint": "^9.30.0",
    "eslint-config-next": "^15.3.4",
    "eslint-config-prettier": "^10.1.1",
    "postcss": "^8.4.31",
    "prettier": "^3.5.3",
    "speed-measure-webpack-plugin": "^1.5.0",
    "tailwindcss": "^3.4.1",
    "typescript": "^5",
    "webpack": "^5.98.0",
    "webpack-cli": "^6.0.1",
    "webpack-dev-server": "^5.2.1"
  }
}

vercel.json:

{
    "redirects": [
      {
        "source": "/consult-us-car-consultancy",
        "destination": "/consultation",
        "permanent": true
      }
    ]
  }

next.config.ts:
i

mport type { NextConfig } from "next";
import type { Configuration as WebpackConfiguration } from "webpack";

// Helper function to parse a single domain environment variable
const parseBackendUrl = (envVariable: string | undefined): Array<{
  protocol: "http" | "https";
  hostname: string;
  port?: string;
  pathname: string;
}> => {
  if (!envVariable) return [];
  try {
    // Clean up the URL in case it has @next.config.ts or other artifacts
    const cleanUrl = envVariable.split('@')[0].trim();
    const url = new URL(cleanUrl);
    return [
      {
        protocol: url.protocol.replace(":", "") as "http" | "https", // Remove the trailing ":"
        hostname: url.hostname,
        port: url.port || undefined, // Include port if present
        pathname: "/**", // Match all paths under this domain
      },
    ];
  } catch (error) {
    console.error(`Invalid URL in NEXT_PUBLIC_BACKEND_URL: ${envVariable}`);
    return [];
  }
};

// Parse the backend URL into a remotePatterns array
const remotePatterns = parseBackendUrl(process.env.NEXT_PUBLIC_BACKEND_URL);

const nextConfig: NextConfig = {
  async headers() {
    return [
      {
        source: "/(.*)", // Match all routes
        headers: [
          {
            key: "Cache-Control",
            value: "no-store", // Disable caching for dynamic content
          },
        ],
      },
    ];
  },
  images: {
    remotePatterns, // Use the dynamically parsed backend URL
  },
  experimental: {
    optimizeCss: true, // Enable critical CSS extraction
  },
  webpack(config: WebpackConfiguration) {
    config.optimization = {
      ...config.optimization,
      splitChunks: {
        chunks: "all",
        minSize: 20000,
        maxSize: 300000, // Set appropriate size limits for code splitting
      },
    };

    return config;
  },
  typescript: {
    ignoreBuildErrors: false, // Enforce stricter TypeScript checks
  },
};

export default nextConfig;

Hey, Wisdom :smiley:

Have you taken a look at this thread? Might be helpful!

When you run this build locally, are you using next build or vercel build? The latter is closer to the way Vercel runs it, which might get you matching behavior in dev/prod

This is an annoying error that can be caused by a few different things, but basically Next builds your app and compiles a route manifest, then it looks up in that manifest for a matching lambda (serverless function)

The first thing I see is β—‹ /adminpage/manage/consultancy does not have a Ζ’ which makes it a static file, and therefore should not have a lambda in the first place. You can try setting export const dynamic = 'force-dynamic' to force Next to make a function for it. If that fixes it, then this feels like a Next.js bug since it’s clearly showing it understands it’s static in the same build process

One common cause (which doesn’t look like you have it set up) is i18n settings that confuse Next over whether /en/ is in the function name or not

Another option is to enable Partial Pre-rendering, which is generally a good idea for any site and it changes how this system works, so if you’re running into a weird bug right now then that might get you around it

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.