this Astro project was already deployed on Netlify without SSR and working just fine.
Once I changed it to SSR and tried a new build I got this error.
9:48:06 AM: 08:48:06 AM [build] output target: server
9:48:06 AM: 08:48:06 AM [build] deploy adapter: @astrojs/netlify/functions
9:48:06 AM: 08:48:06 AM [build] Collecting build info...
9:48:06 AM: 08:48:06 AM [build] Completed in 1.47s.
9:48:06 AM: 08:48:06 AM [build] Building server entrypoints...
9:48:09 AM: 08:48:09 AM [build] Completed in 3.11s.
9:48:09 AM:
9:48:09 AM: building client
9:48:10 AM: Completed in 1.30s.
9:48:10 AM:
9:48:10 AM:
9:48:10 AM: prerendering static routes
9:48:10 AM: error Cannot read properties of undefined (reading 'length')
9:48:10 AM: File:
9:48:10 AM: /opt/build/repo/node_modules/astro/dist/core/build/generate.js:66:20
9:48:10 AM: Code:
9:48:10 AM: 65 | const ssrEntryURL = new URL("./" + serverEntry + `?time=${Date.now()}`, outFolder);
9:48:10 AM: > 66 | const ssrEntry = await import(ssrEntryURL.toString());
9:48:10 AM: | ^
9:48:10 AM: 67 | const builtPaths = /* @__PURE__ */ new Set();
9:48:10 AM: 68 | if (opts.settings.config.output === "server") {
9:48:10 AM: 69 | for (const pageData of eachPrerenderedPageData(internals)) {
9:48:10 AM: Stacktrace:
9:48:10 AM: TypeError: Cannot read properties of undefined (reading 'length')
9:48:10 AM: at file:///opt/build/repo/.netlify/functions-internal/chunks/pages/all.bcf310be.mjs:1556:17
9:48:10 AM: at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
9:48:10 AM: at async Promise.all (index 0)
9:48:11 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:48:10 AM: at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
9:48:10 AM: at async generatePages (file:///opt/build/repo/node_modules/astro/dist/core/build/generate.js:66:20)
9:48:10 AM: at async staticBuild (file:///opt/build/repo/node_modules/astro/dist/core/build/static-build.js:85:7)
9:48:10 AM: at async AstroBuilder.build (file:///opt/build/repo/node_modules/astro/dist/core/build/index.js:122:5)
9:48:10 AM: at async AstroBuilder.run (file:///opt/build/repo/node_modules/astro/dist/core/build/index.js:153:7)
9:48:10 AM: at async build (file:///opt/build/repo/node_modules/astro/dist/core/build/index.js:37:3)
9:48:10 AM: at async runCommand (file:///opt/build/repo/node_modules/astro/dist/cli/index.js:168:14)
9:48:10 AM: at async cli (file:///opt/build/repo/node_modules/astro/dist/cli/index.js:203:5)
9:48:10 AM:
9:48:10 AM: "build.command" failed
I checked multiple times on the Astro and Netlify docs if I missed something but it doesn't seem to be the case. Astro.config:
import netlify from "@astrojs/netlify/functions";
output: 'server',
adapter: netlify()
On Netlify I activated prerendering in Site settings > Build & deploy > Post processing > Prerendering.