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
13 Replies
firebase-admin
looks to be a long-running server, so no, it won't work on Pages.
?pages-webserverCloudflare 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.
I'm using this (with sveltekit) https://blog.cloudflare.com/cloudflare-pages-goes-full-stack/
The Cloudflare Blog
Cloudflare Pages Goes Full Stack
Cloudflare Pages with Functions is now in open beta!
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?
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
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
My understanding is Vercel has two type of serverless runtimes, Edge functions which run on CF, and serverless functions which run on aws
if it could just build with the polifils, maybe it should work
hmm I see
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?
already using the v2 ![sad](https://cdn.discordapp.com/emojis/1002546378645438564.png)
![sad](https://cdn.discordapp.com/emojis/1002546378645438564.png)
@ceifa have you been able to solve this? I'm also trying to use
firebase-admin
in Cloudflare Workersnop, 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
Ok, thanks for the update.