Hello everyone,
i am using Astro with the Cloudflare integration and want to "auto" generate my translation files by fetching them from a standalone backend service during build.
So I thought i could write a build script using NodeJS (as this should be available at least during build) fetching the translations from my backend and saving these into one json file per language under src/i18n/common.
I added the script to run before anything astro does in my package.json like this:
"scripts": {
"fetch-translations": "node scripts/i18n-fetch.js",
"dev": "npm run fetch-translations && astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro",
"i18n-fetch": "npm run fetch-translations",
"i18n:extract": "astro-i18n extract",
"i18n:generate:pages": "astro-i18n generate:pages --purge",
"i18n:generate:types": "astro-i18n generate:types",
"i18n:sync": "npm run i18n:generate:pages && npm run i18n:generate:types"
},
But when building Astro locally, i now get the following error:
[commonjs--resolver] [plugin vite:resolve] Cannot bundle Node.js built-in "fs" imported from "node_modules\esbuild\lib\main.js". Consider disabling ssr.noExternal or remove the built-in dependency.
file: ...../frontend-website/node_modules/esbuild/lib/main.js
So I understand that libraries, especially node-fs are not compatible with Cloudflare workers at runtime , but I thought this should work at build time.
Would be glad if someone could point me in the right direction to solve my issue, Cheers!