I have been working on a small side project where I have gone full CI/CD with GitHub Container Registry. I write the code in JavaScript and then push the code to my repo, and a GitHub Action will create a Docker container and then publish it to the Container Registry. From the registry, I am able to pull and deploy it in the VPS of my cloud provider.

I am a big fan of PrismaJS as an ORM that saves me time writing SQL queries and setting up my database and relationships. Starting from PrismaJS version 7, they require you to provide an output path for the generated ORM to be saved, and prior to V7, it was saved inside the node_modules folder.

As I was getting this warning to provide an output path before it hits V7, I provided an output path and moved on. It was working perfectly on my computer, but when I started deploying the Docker image, it seemed to crash. Not exactly what I wanted. “It works on my computer” is not an excuse I like to give anyone.

When I read the Docker logs, I realized the issue: it was complaining about not being able to find the __dirname variable. This is something common when you are not using ESM modules. After some Googling, I found that this is something people have been complaining about for some time: Issue #15614 and Issue #20702.

I tried some of the solutions mentioned in the threads, but I was still getting the error in Docker. Yet without these fixes, it was working perfectly on my computer.

But it was working fine on my computer; I did not get this error (Again, not the excuse I would like to give, even for myself). So why was my Docker container failing?

Then I realized that I am using Node.js as the base image for my Docker, when I am using Bun in development. And Bun has a way of not caring whether you’re using ESM or CommonJS JavaScript—you can mix and write code and it just works. I want something that just works.

So after wasting a whole afternoon trying to fix this issue, I thought I’d just switch the base image to Bun from Node. And after switching from Node.js to Bun, everything started working smoothly again.

But something else I found interesting after switching is the build time: where it took me about 5 minutes for the Node.js container to build, it took only 2 minutes and 30+ seconds to build the same container in Bun. Also, the build size was reduced from 500+ MB to 300+ MB.

This is a really good save when it comes to both build time and bandwidth. The Node.js image uses Alpine Linux, which is quite small, compared to the Debian Slim used by Bun. But the overall final output was smaller and builds faster. So I don’t know what’s the difference that makes the build size smaller for Bun over Node. I can imagine Bun being considerably faster is why the build time is less in Bun compared to Node.

So I am happy using the Bun image and will continue to use it for now. Also, as an update, someone has posted a fix to the PrismaJS issue on the GitHub thread, so I think the issue can be solved by following those instructions, which would make it work in Node.js as well. Comment #2857932479

But then again, considering the build time and build size, I will stay with Bun for now for this project.