Issue Deploying Next.js 13 with Bun 1.0
For better or worse I've decided to follow the hype train and am trying to get Bun 1.0 working with my Next.js 13 project on railway. Prior to using Bun the project has been deploying perfectly fine. I have followed the many threads already made here about Bun and am using the special Nixpkgs archive to make sure I have bun 1.0 available.
The funky thing is the project actually appears to build fine. Meaning there are no errors during the build. An image is produced and then it's deployed. The error only occurs during actually running the app when I get the following error:
This causes the deployment to error out and consider itself "completed" not "active". I have tried building then running the package locally on my M2 macbook and it works fine.
The only final clue I can offer is that weirdly the output during the build step is missing the Next.js route type output. That part where it tells you what route will be what. SSR, Static, etc. It appears on my local computer, but not during the build on railway and it definitely used to when using pure yarn/node.
However, it again does not produce and error, there's just no output:
52 Replies
Project ID:
d56d2d18-a224-4e42-89ad-f6d1f43b6b55
d56d2d18-a224-4e42-89ad-f6d1f43b6b55
Larger snippet of the build log
Potentially related github issue on Bun: https://github.com/oven-sh/bun/issues/4795
GitHub
Bun + Nextjs + Docker: Incomplete .next build output in docker, but...
What version of Bun is running? 1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983 What platform is your computer? Linux 6.2.0-32-generic x86_64 x86_64 What steps can reproduce the bug? git clone git@g...
not much we can do for you if this is a bun issue
I'm not sure it's a bun issue persay. Again it works fine on my local machine, just on railway it seems like for whatever reason the proper Next.js files aren't built or put in the right place
railway does use docker, and if bun isn't playing nicely in a docker environment there's again not much we can do for you here
Are you aware of anyone getting Next.js and bun to work on railway because this is currently a blocker for me. That issue I pointed out might be the cause, but it was just something that seemed similar. I'm still worried I'm potentially doing something dumb.
i am not aware of anyone who got Next.js and bun to work on railway
Not sure, but maybe this can help?
https://stackoverflow.com/questions/76897466/dockerize-next-js-13-docker-compose-yml
Hmm that's interesting but to be clear I'm not directly using docker. I'm using Nixpacks. Hence why I'm asking for help here
nixpacks uses docker
I understand that, but then how would you implement this given there's no docker yml file
https://stackoverflow.com/a/76898046/6575991? Is it something in Nixpack toml?
Stack Overflow
Dockerize next.js 13 docker-compose.yml
I'm building a next.js 13 app, I want to dockerize it.
My docker file Dockerfile is working but now I want to use docker-compose.yml file to use my dockerfile.
I tried old versions new versions light
nixpacks runs
npm run build
if you have a build script in your package.jsonHmm maybe I'm not understanding you or I wasn't clear in the beginning. But basically all I have changed is switching to Bun. Before that I was using no additional config on Railway. It detected it was a Next.js project and my build command is 'bun run build' and my start command is 'bun run start' with those mapping to: 'next build' and 'next start' respectively. Everything worked fine. I'm only sticking with this because I figured some other people may come across this issue as well. I'm not even sure what the issue is, but for whatever reason when the deploy step runs my start command it fails with my above error message
@mfrankel I have tried this and for me it worked (https://testnext-production.up.railway.app) adding nodejs to nixconfig
nixpacks.toml
maybe give it a try
(using also Bun)
drop the scripts
drop the nixpacks build table
Build logs you mean?
just the build table
you sent the scripts as a code block but not the build table lol
the whitespace lines!!
now? 😅
something makes me think next is starting with node
but there's
bun run start
...yes bun is executing the start script, but what if next is starting itself with node
oh you mean next start finds node and uses that?
yeah
can you print some runtime information to the web page?
like?
wait if I try using some Bun apis it shouldn't work if it's using node
like Bun.sleep
like what runtime is in use lol
that's boring though, we wanna see juicy runtime information
where do I get it?
from process?
no clue, you are the node developer lol
I almost exclusively do go
called it
drop the repo
no repo
just railway up
guess i cant work my magic
wym
how can i get a next app to run with bun on railway without having a next app to run on railway?
bun x create-next-app
railway init
railway up
😅
im on windows
don't you have WSL?
hell no
What's all that hate? 😂
🤣
I'll give these changes a try right now. If it's worth anything in terms of the whole next on node vs next on bun debate you guys were having according to Bun's website it actually falls back to running Next.js on Bun. https://bun.sh/guides/ecosystem/nextjs
"Next.js currently relies on Node.js APIs that Bun does not yet implement. The guide below uses Bun to initialize a project and install dependencies, but it uses Node.js to run the dev server."
However worth noting this block of text pre-dates the 1.0 release so maybe this has changed...
Either way I remain cautiously optimistic in fedev's solution give maybe it needs an explicit node runtime because of this.
Okay so progress! It's finally showing output from Next.js. I ran into an issue with it error-ing out because of an issue with Sharp, but I will try to debug
The issue is it not finding sharp:
Cannot find module '../build/Release/sharp-linux-x64.node'
I think this has to do with how Bun installs it. I had to do a manual workaround on my mac
Searching for workarounds within Nixpacks/docker but seems to relate to this issue:
https://github.com/oven-sh/bun/issues/606
GitHub
Support NPM Life Cycle Hook Scripts · Issue #606 · oven-sh/bun
What is the problem this feature will solve? Many libraries currently depend on life cycle hooks for automated actions such as downloading a binary for a specific platform. What is the feature you ...
Okay so I think I got to as close to success as is possible now. I have a build running where Bun is the primary installer. Sadly it seems until that above 606 issue gets fixed you need to use NPM to install sharp again.
This is my working config to get Bun deploying a Next.js project on railway!
Okay that can be slightly improved to this version:
Were you rebuild instead of reinstall. It cut the npm step time down by half
There's a chance it could be made even faster by using pnpm but given this should hopefully be a temporary stop-gap I'm not going to spend the time
still seems like next would be building and running with node