Polyák Csaba E.V. 👑💎 +5 2025. 04. 24. 4:00:00
Klasszikus Astro 5 + Cloudflare Workers buktató. A node_compat hiánya, vagy egy függőség ami process.env.NODE_ENV-re hivatkozik runtime-on.
Gyors fix:
*1. Az astro.config.mjs-be add hozzá a cloudflare adapter platformProxy opciót:*
import { defineConfig } from "astro/config";
import cloudflare from "@astrojs/cloudflare";
export default defineConfig({
output: "server",
adapter: cloudflare({
platformProxy: { enabled: true },
imageService: "compile",
}),
});
2. Ha statikus Astro (output: "static"), akkor a vite.define-ot kell használni hogy a build-time helyettesítse a process.env.*-okat üresre:
export default defineConfig({
output: "static",
vite: {
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
"process.env": "({})",
},
},
});
3. Ellenőrizd a függőségeidet — npm ls | grep -i "process\|node:process" vagy a node_modules átfutása. Néhány csomag (pl. régi dotenv, chalk v3-) build-time helyett runtime-on hivatkozik a process-re. Ha találsz ilyet, frissítsd a legújabbra (a v4+ Edge-compatible) vagy cseréld ki egy kompatibilisre.
4. Ha még mindig megy a hiba: kapcsold be a wrangler.toml-ban a node_compat = true-t (vagy a CF Pages dashboard-on a Settings → Functions → Compatibility flags-nél a nodejs_compat-ot). Ez +1MB build-output, de a legtöbb Node-API működni fog.
Ha melyik ágon vagy, és a hibaüzenet teljes stack trace-e is megvan, írd ide és segítek célzottan!