Replies: 1 comment
-
|
would be cool making this work |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm not sure if this is possible at all, but I'm running into issues when compiling
.next/standalone/server.jsinto a binary for use in a container image.When I try using
bun build --compile, it fails to resolve any of the CommonJSrequire()dependencies, even when I call it from within the.next/standalonedirectory. This causes the entire compilation process to fail, and I don't get a binary produced.I also tried the
@yao-pkg/pkgmodule, which does actually produce a binary, but when you try to run it, the binary fails because it's trying tochdirto a weird directory (/snapshot/$app/.next/standalone) which doesn't exist.Why?
The Next.js recommended Dockerfile is both useful and very efficient when it comes to building container images, but I was wondering whether the final image size could be reduced a bit by compiling the Next.js application server into a static binary first, and then copying that over to the final image. This would let you source the runtime stage
FROM alpinerather than thenode:18-alpinebase image, which I hypothesized might make the final image size a lot smaller, since it doesn't need to include anything else related to Node.js development (likenpmorcorepack) which might be included in a general Node.js base image.Other deployment methods may also benefit from this approach. For example, Tauri currently doesn't support the Next.js server in production, but it does support bundling a Node.js sidecar application to run, which theoretically could include a web server. This means it may be possible to run a "fully-featured" Next.js app as the frontend to a Tauri native application, if the server could be compiled to a binary...
Additional information
Not sure if anyone else has tried this before, or whether anyone went down this path and found out it really doesn't matter either way...I can see that because the whole bun/node runtime needs to be included in the executable, so maybe it's just a negligible improvement?
Example
Here's what the (slightly edited for brevity) Dockerfile might look like if this was possible:
And here's what it might look like using Bun:
Beta Was this translation helpful? Give feedback.
All reactions