R
Railway14mo ago
Marc

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:
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
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
#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
52 Replies
Percy
Percy14mo ago
Project ID: d56d2d18-a224-4e42-89ad-f6d1f43b6b55
Marc
Marc14mo ago
d56d2d18-a224-4e42-89ad-f6d1f43b6b55
Marc
Marc14mo ago
Larger snippet of the build log
Marc
Marc14mo ago
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...
Brody
Brody14mo ago
not much we can do for you if this is a bun issue
Marc
Marc14mo ago
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
Brody
Brody14mo ago
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
Marc
Marc14mo ago
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.
Brody
Brody14mo ago
i am not aware of anyone who got Next.js and bun to work on railway
Marc
Marc14mo ago
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
Brody
Brody14mo ago
nixpacks uses docker
Marc
Marc14mo ago
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
Brody
Brody14mo ago
nixpacks runs npm run build if you have a build script in your package.json
Marc
Marc14mo ago
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
fedev
fedev14mo ago
@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']
[phases.setup]
nixpkgsArchive = 'c054b2a07bce2be3b85fed85f45aea6a4b97f5cc'
nixPkgs = ['...', 'nodejs_18']
maybe give it a try (using also Bun)
Brody
Brody14mo ago
drop the scripts
fedev
fedev14mo ago
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
Brody
Brody14mo ago
drop the nixpacks build table
fedev
fedev14mo ago
Build logs you mean?
Brody
Brody14mo ago
just the build table
fedev
fedev14mo ago
╔══════ Nixpacks v1.14.0 ══════╗
║ setup │ bun, nodejs_18 ║
║──────────────────────────────║
║ install │ bun i --no-save ║
║──────────────────────────────║
║ build │ bun run build ║
║──────────────────────────────║
║ start │ bun run start ║
╚══════════════════════════════╝
╔══════ Nixpacks v1.14.0 ══════╗
║ setup │ bun, nodejs_18 ║
║──────────────────────────────║
║ install │ bun i --no-save ║
║──────────────────────────────║
║ build │ bun run build ║
║──────────────────────────────║
║ start │ bun run start ║
╚══════════════════════════════╝
Brody
Brody14mo ago
you sent the scripts as a code block but not the build table lol
fedev
fedev14mo ago
mildpanicintensifies
Brody
Brody14mo ago
the whitespace lines!!
fedev
fedev14mo ago
now? 😅
Brody
Brody14mo ago
something makes me think next is starting with node
fedev
fedev14mo ago
but there's bun run start ...
Brody
Brody14mo ago
yes bun is executing the start script, but what if next is starting itself with node
fedev
fedev14mo ago
oh you mean next start finds node and uses that?
Brody
Brody14mo ago
yeah can you print some runtime information to the web page?
fedev
fedev14mo ago
like? wait if I try using some Bun apis it shouldn't work if it's using node like Bun.sleep
Brody
Brody14mo ago
like what runtime is in use lol that's boring though, we wanna see juicy runtime information
fedev
fedev14mo ago
where do I get it? from process?
Brody
Brody14mo ago
no clue, you are the node developer lol I almost exclusively do go
fedev
fedev14mo ago
okk seems like process.versions https://testnext-production.up.railway.app/ doesen't seem good
Brody
Brody14mo ago
called it drop the repo
fedev
fedev14mo ago
no repo just railway up
Brody
Brody14mo ago
guess i cant work my magic
fedev
fedev14mo ago
wym
Brody
Brody14mo ago
how can i get a next app to run with bun on railway without having a next app to run on railway?
fedev
fedev14mo ago
bun x create-next-app railway init railway up 😅
Brody
Brody14mo ago
im on windows
fedev
fedev14mo ago
don't you have WSL?
Brody
Brody14mo ago
hell no
fedev
fedev14mo ago
What's all that hate? 😂
Brody
Brody14mo ago
🤣
Marc
Marc14mo ago
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.
Marc
Marc14mo ago
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
Marc
Marc14mo ago
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 ...
Marc
Marc14mo ago
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',
]
[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',
]
[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
Brody
Brody14mo ago
still seems like next would be building and running with node
Want results from more Discord servers?
Add your server