#Astro cloudflare + node-fs at buildtime issue

8 messages · Page 1 of 1 (latest)

lean salmon
#

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!

dusk radish
#

@lean salmon hey did you managed to solve this iam also going through same thing

lean salmon
#

@dusk radish not willingly, the error disappeared some days ago but i dont know why 😄

#

Also I did not yet deploy my astro project to cloudflare to test it there. will do so in about a week i think and head back if theres any news

dusk radish
#

still cloudflare pages is real pain iam trying to deploy keystatic + Astro site to cloudflare pages and node:fs have issues

lean salmon
#

whats the cause of node-fs usage on your project ?

dusk radish
#

Keystatic package use it

lean salmon
#

Oh thats even worse, as you are not in control. sadge