R
Railway

✋|help

Issue Deploying Next.js 13 with Bun 1.0

Mmfrankel9/11/2023
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:

next start -p process.env.PORT
- ready started server on localhost:34497, url: http://localhost:34497
ENOENT: No such file or directory
path: "/app/.next/BUILD_ID"
syscall: "open"
errno: -2


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:

#12 0.445 $ next build
#12 1.659 - warn You have enabled experimental features (serverActions, serverComponentsExternalPackages) in next.config.js.

#12 1.659 - warn Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

#12 1.660
#12 1.943 - info Creating an optimized production build...
#12 DONE 30.9s


#13 [stage-0  9/10] RUN printf '\nPATH=/app/node_modules/.bin:$PATH' >> /root/.profile 

#13 DONE 0.4s

#14 [stage-0 10/10] COPY . /app 

#14 DONE 0.1s

#15 exporting to image
#15 exporting layers
Mmfrankel9/11/2023
d56d2d18-a224-4e42-89ad-f6d1f43b6b55
Mmfrankel9/11/2023
Larger snippet of the build log
Mmfrankel9/11/2023
Potentially related github issue on Bun: https://github.com/oven-sh/bun/issues/4795
Bbrody1929/11/2023
not much we can do for you if this is a bun issue
Mmfrankel9/11/2023
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
Bbrody1929/11/2023
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
Mmfrankel9/12/2023
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.
Bbrody1929/12/2023
i am not aware of anyone who got Next.js and bun to work on railway
Mmfrankel9/12/2023
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
Bbrody1929/12/2023
nixpacks uses docker
Mmfrankel9/12/2023
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?
Bbrody1929/12/2023
nixpacks runs npm run build if you have a build script in your package.json
Mmfrankel9/12/2023
Hmm 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
Ffedev1009/13/2023
@mfrankel I have tried this and for me it worked (https://testnext-production.up.railway.app) adding nodejs to nixconfig

nixpacks.toml
[phases.setup]
nixpkgsArchive = 'c054b2a07bce2be3b85fed85f45aea6a4b97f5cc'
nixPkgs = ['...', 'nodejs_18']

maybe give it a try
(using also Bun)
Bbrody1929/13/2023
drop the scripts
Ffedev1009/13/2023
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  }
Bbrody1929/13/2023
drop the nixpacks build table
Ffedev1009/13/2023
Build logs you mean?
Bbrody1929/13/2023
just the build table
Ffedev1009/13/2023
╔══════ Nixpacks v1.14.0 ══════╗
║ setup      │ bun, nodejs_18  ║
║──────────────────────────────║
║ install    │ bun i --no-save ║
║──────────────────────────────║
║ build      │ bun run build   ║
║──────────────────────────────║
║ start      │ bun run start   ║
╚══════════════════════════════╝
Bbrody1929/13/2023
you sent the scripts as a code block but not the build table lol
Ffedev1009/13/2023
:mildpanicintensifies:
Bbrody1929/13/2023
the whitespace lines!!
Ffedev1009/13/2023
now? 😅
Bbrody1929/13/2023
something makes me think next is starting with node
Ffedev1009/13/2023
but there's bun run start ...
Bbrody1929/13/2023
yes bun is executing the start script, but what if next is starting itself with node
Ffedev1009/13/2023
oh you mean next start finds node and uses that?
Bbrody1929/13/2023
yeah
can you print some runtime information to the web page?
Ffedev1009/13/2023
like?
wait if I try using some Bun apis it shouldn't work if it's using node
like Bun.sleep
Bbrody1929/13/2023
like what runtime is in use lol
that's boring though, we wanna see juicy runtime information
Ffedev1009/13/2023
where do I get it?
from process?
Bbrody1929/13/2023
no clue, you are the node developer lol
I almost exclusively do go
Ffedev1009/13/2023
okk seems like process.versions
https://testnext-production.up.railway.app/
doesen't seem good
Bbrody1929/13/2023
called it
drop the repo
Ffedev1009/13/2023
no repo
just railway up
Bbrody1929/13/2023
guess i cant work my magic
Ffedev1009/13/2023
wym
Bbrody1929/13/2023
how can i get a next app to run with bun on railway without having a next app to run on railway?
Ffedev1009/13/2023
bun x create-next-app
railway init
railway up
😅
Bbrody1929/13/2023
im on windows
Ffedev1009/13/2023
don't you have WSL?
Bbrody1929/13/2023
hell no
Ffedev1009/13/2023
What's all that hate? 😂
Bbrody1929/13/2023
🤣
Mmfrankel9/13/2023
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
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.
[phases.setup]
nixpkgsArchive = 'c054b2a07bce2be3b85fed85f45aea6a4b97f5cc'
nixPkgs = ['...', 'nodejs_18']

[phases.install]
cmds = [
    'bun i --no-save',
    'npm install --platform=linux --arch=x64 sharp',
]

This is my working config to get Bun deploying a Next.js project on railway!
Okay that can be slightly improved to this version:
[phases.setup]
nixpkgsArchive = 'c054b2a07bce2be3b85fed85f45aea6a4b97f5cc'
nixPkgs = ['...', 'nodejs_18']

[phases.install]
cmds = [
    'bun i --no-save',
    'npm rebuild --platform=linux --arch=x64 sharp',
]

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
Bbrody1929/13/2023
still seems like next would be building and running with node

Looking for more? Join the community!

Recommended Posts
Pricing QuestionsI'm looking for some clarification regarding Railway's pricing structure. I've noticed that the 'HobDeploying via github always crashes after 4-5 minutesI am creating a discord bot and when I commit to github and deploy it, it starts fine at first. But Deploying bun 1.0in bun cause I don't need to build files is their somehow I can skip the build step since it alreadyWhere can you store Media Files?I'm using Django and have added a blog module to it where users can upload their own images. I was wEasy (?) shared variables questionThe environment contains the excellent Payload CMS template, attendant Mongo DB, and a Next.js frontPlan update issueIm having a issue with plan update. It just shows: Problem processing payment method and I triple cCan't create an account: Device requesting login is not supported. Please try again from a secure coTrying to create a new Railway Account, but getting this error: ```Device requesting login is not saccess to resource inside replicahi, when we setup an instance to have 2 replicas, how do we get the resource related to 1 of the reCommunicate between services with private networkProject ID: 3f51dcb4-6905-4a13-be75-4c6063e4324a I am trying to set up Railway to communicate betweWeb Server Not WorkingI just started a small simple web server. I generated a custom domain for now, and when trying to achttp://0.0.0.0:8000 to urlI am using a Django REST framework. When I query the URL at 0.0.0.0:8000 I can get a response, but aOpenSearch deploymentHi everyone. I require assistance with deploying an instance of OpenSearch since I get an error durUnable to connect with private networkHey guys, I'm a bit unsure on how to use the internal network. I have a .net api that has a privaterclone on railway to transfer data from one cloud to an other.Hello, I'm creating an app the requires to transfer data from one cloud storage (like onedrive to aBun 1.0 on railwayI am spinning up a simple bun app with 1 file in it. But for some reason all of my builds are failinSocket cannot be archivedWhen building the railway project I get a message saying that: /Users/x/Library/Application SupportBUN 1.0 + AstroHas anyone tried to deploy a Bun app yet? I am getting this error. ERROR: failed to solve: processDjango Railway admin consoleHi! I've had a really good time using Railway thus far, sea-change from setting up an EC2 instance Trouble sending emails via SMTPprojectId: `bb66f5c0-53f9-4e9f-b11f-5965f5d6ec74` serviceId: `b3029692-b78a-4487-bcb0-44e001afecb8` Cannot have a TCP proxy and a domainWhen trying to create a service with a proxy, I'm getting this error. Can I not have a TCP proxy ser