Using builtin node packages on build process cause errors

hello, is it possible to have firebase-admin on cloudflare pages? it keeps getting an error on build, because it relies on node packages
error during build:
Error: Build failed with 158 errors:
node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:3:31: ERROR: Could not resolve "stream"
node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:4:25: ERROR: Could not resolve "util"
node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:3:29: ERROR: Could not resolve "events"
node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:4:25: ERROR: Could not resolve "util"
node_modules/@fastify/busboy/deps/dicer/lib/PartStream.js:3:25: ERROR: Could not resolve "util"
error during build:
Error: Build failed with 158 errors:
node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:3:31: ERROR: Could not resolve "stream"
node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js:4:25: ERROR: Could not resolve "util"
node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:3:29: ERROR: Could not resolve "events"
node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js:4:25: ERROR: Could not resolve "util"
node_modules/@fastify/busboy/deps/dicer/lib/PartStream.js:3:25: ERROR: Could not resolve "util"
13 Replies
James
James2y ago
firebase-admin looks to be a long-running server, so no, it won't work on Pages. ?pages-webserver
Flare
Flare2y ago
Cloudflare Pages is for static content (HTML, CSS, JS, images and other such files). It will not run a webserver such as Express, Koa or the likes. If you're using those to serve static content then you can just remove that part and use Pages! If you're doing more dynamic content you can use Functions (https://developers.cloudflare.com/pages/platform/functions). It will run code on request (so still not a webserver in the conventional sense). This would allow for more dynamic content though especially with KV (Key Value storage) and Durable Objects (transactional data storage). Functions are natively integrated with Pages so are super easy to get up and running along your website. Otherwise, a good old VPS or dedicated server from one of the many hosts out there is for you.
ceifa
ceifaOP2y ago
The Cloudflare Blog
Cloudflare Pages Goes Full Stack
Cloudflare Pages with Functions is now in open beta!
ceifa
ceifaOP2y ago
so it will run the firebase-admin on a worker but actually the problem is on build process no solutions? is it possible to enable the compat mode on page functions?
Chaika
Chaika2y ago
It is, but that's not going to help you here most likely. Node compat mode adds support for a few nodejs things like buffer, etc, but fundamentally Cloudflare Workers have no support creating sockets, Workers are short lived, spun up when needed, etc. It looks like Firebase admin is trying to use Fastify, a nodejs web framework, which just isn't going to work
ceifa
ceifaOP2y ago
the weird thing is that the code works on vercel, which is short lived too my code doesn't use the firebase-admin part that uses sockets, etc
Chaika
Chaika2y ago
My understanding is Vercel has two type of serverless runtimes, Edge functions which run on CF, and serverless functions which run on aws
ceifa
ceifaOP2y ago
if it could just build with the polifils, maybe it should work hmm I see
Chaika
Chaika2y ago
Ahh sorry I missed the build part before, If that error is happening during build, and you're using the default Build Image v1, it defaults to nodejs 12 (too old for firebase-admin, looks like). You can increase that via "NODE_VERSION" environment variable, or by switching to Build Image v2 which defaults to 18. I haven't used Firebase admin before, but you aren't using the part that uses sockets, you might be fine?
ceifa
ceifaOP2y ago
already using the v2 sad
Elie Zedeck R.
@ceifa have you been able to solve this? I'm also trying to use firebase-admin in Cloudflare Workers
ceifa
ceifaOP2y ago
nop, using vercel just because of that :/ I saw people trying to fix it in different ways and failing, so I gave up this is a limitation from cloudflare workers by not supporting some node builtins it will probably be fixed later, but not possible for now
Elie Zedeck R.
Ok, thanks for the update.
Want results from more Discord servers?
Add your server