https://discord.cloudflare.com logo
Using builtin node packages on build process cause errors
c

ceifa

05/25/2023, 6:50 PM
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"
j

James

05/25/2023, 6:56 PM
firebase-admin
looks to be a long-running server, so no, it won't work on Pages.
?pages-webserver
h

Helpflare

05/25/2023, 6:56 PM
> 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.
c

ceifa

05/25/2023, 8:02 PM
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?
c

Chaika

05/28/2023, 7:23 PM
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
c

ceifa

05/28/2023, 7:50 PM
my code doesn't use the firebase-admin part that uses sockets, etc
c

Chaika

05/28/2023, 7:50 PM
My understanding is Vercel has two type of serverless runtimes, Edge functions which run on CF, and serverless functions which run on aws
c

ceifa

05/28/2023, 7:50 PM
if it could just build with the polifils, maybe it should work
hmm I see
c

Chaika

05/28/2023, 8:13 PM
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?