R
Railway11mo ago
_typedev

Next 14 with bun 1.0.7

Hey there I'm wondering if I may get some clarification on how to correctly configure my Railway.json 1. What is the proper type for NIXPACKS_NO_CACHE I'm assuming it should be a string value of "1" in this case? 2. When adding a nixPkgsArchive I'm not seeing the proper version get installed. I've tried a few things 1. I assumed that maybe because I was passing "bun" in nixPkgs that it was interferring with the isntallation of the pckgArchive 2. I tried both ways and no lucj My assumption is that I'm not properly working with the cache. And ould appreciate any documentation you all may offer up so I may do may read up on it. Thanks!
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"watchPatterns": ["apps/next/**"],
"nixpacksPlan": {
"phases": {
"build": {
"cmds": ["bun run --cwd \"apps/next\" build"],
"dependsOn": ["install"],
"cacheDirectories": ["apps/next/.next/cache", "node_modules/.cache"]
},
"setup": {
"nixPkgs": ["nodejs_20", "bun"],
"nixOverlays": ["https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz"],
"nixPkgsArchive": "a3d8834fae7c986033e72db669239cd9c1cedc96"
},
"install": {
"cmds": ["bun i"],
"paths": ["/app/node_modules/.bin"],
"dependsOn": ["setup"],
"cacheDirectories": ["/root/.bun"]
}
},
"providers": [],
"variables": {
"CI": "true",
"NODE_ENV": "production",
"NIXPACKS_METADATA": "node",
"NIXPACKS_NO_CACHE": "1",
"NPM_CONFIG_PRODUCTION": "false"
},
"buildImage": "ghcr.io/railwayapp/nixpacks:ubuntu-1697500996"
}
},
"deploy": {
"startCommand": "bun run --cwd \"apps/next\" start",
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"watchPatterns": ["apps/next/**"],
"nixpacksPlan": {
"phases": {
"build": {
"cmds": ["bun run --cwd \"apps/next\" build"],
"dependsOn": ["install"],
"cacheDirectories": ["apps/next/.next/cache", "node_modules/.cache"]
},
"setup": {
"nixPkgs": ["nodejs_20", "bun"],
"nixOverlays": ["https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz"],
"nixPkgsArchive": "a3d8834fae7c986033e72db669239cd9c1cedc96"
},
"install": {
"cmds": ["bun i"],
"paths": ["/app/node_modules/.bin"],
"dependsOn": ["setup"],
"cacheDirectories": ["/root/.bun"]
}
},
"providers": [],
"variables": {
"CI": "true",
"NODE_ENV": "production",
"NIXPACKS_METADATA": "node",
"NIXPACKS_NO_CACHE": "1",
"NPM_CONFIG_PRODUCTION": "false"
},
"buildImage": "ghcr.io/railwayapp/nixpacks:ubuntu-1697500996"
}
},
"deploy": {
"startCommand": "bun run --cwd \"apps/next\" start",
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
Solution:
First of all thanks @Brody ! For anyone currently working with Bun/Next.js/Railway this might be helpful: For me , builds with next.js kept failing, and I’ve tried everything a lot of different methods, and configurations ...
Jump to solution
14 Replies
Percy
Percy11mo ago
Project ID: 1835b3bd-c387-4d79-ace9-a0e10cb05feb
_typedev
_typedev11mo ago
1835b3bd-c387-4d79-ace9-a0e10cb05feb
Brody
Brody11mo ago
you spelt nixPkgsArchive wrong, its spelt nixpkgsArchive
_typedev
_typedev11mo ago
@Brody must have been thrown off then sinceI get this error I'm going to test it now and let you know.
No description
Brody
Brody11mo ago
funny, its spelt nixpkgsArchive in their docs, i say spelt but its just the casing
_typedev
_typedev11mo ago
Going to give it a show, I appreciate the follow-up I saw that you mentioned NIXPACKS_NO_CACHE=1 for skipping caching when using railway.toml Would this be the case for the railway.json?
"variables":{
"NIXPACKS_NO_CACHE": "1",
}
"variables":{
"NIXPACKS_NO_CACHE": "1",
}
Brody
Brody11mo ago
i havent tried setting that variable in a railway.json or even a nixpacks.toml, ive only ever set it in a service variable
_typedev
_typedev11mo ago
I see!
No description
Brody
Brody11mo ago
though if i had to guess you should set it as a service variable instead, since its more so a variable used by the platform
_typedev
_typedev11mo ago
Let me give that a shot too
Brody
Brody11mo ago
if you dont have any luck, just swap the nixpacks stuff to its own nixpacks.toml config file
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"watchPatterns": ["apps/next/**"]
},
"deploy": {
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"watchPatterns": ["apps/next/**"]
},
"deploy": {
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
buildImage = 'ghcr.io/railwayapp/nixpacks:ubuntu-1697500996'

[variables]
CI = 'true'
NODE_ENV = 'production'
NIXPACKS_METADATA = 'node'
NIXPACKS_NO_CACHE = '1'
NPM_CONFIG_PRODUCTION = 'false'

[phases.setup]
nixPkgs = ['nodejs_20', 'bun']
nixOverlays = ['https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz']
nixpkgsArchive = 'a3d8834fae7c986033e72db669239cd9c1cedc96'

[phases.install]
cmds = ['bun i']
paths = ['/app/node_modules/.bin']
dependsOn = ['setup']
cacheDirectories = ['/root/.bun']

[phases.build]
cmds = ['bun run --cwd "apps/next" build']
dependsOn = ['install']
cacheDirectories = ['apps/next/.next/cache', 'node_modules/.cache']

[start]
cmd = 'bun run --cwd "apps/next" start'
buildImage = 'ghcr.io/railwayapp/nixpacks:ubuntu-1697500996'

[variables]
CI = 'true'
NODE_ENV = 'production'
NIXPACKS_METADATA = 'node'
NIXPACKS_NO_CACHE = '1'
NPM_CONFIG_PRODUCTION = 'false'

[phases.setup]
nixPkgs = ['nodejs_20', 'bun']
nixOverlays = ['https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz']
nixpkgsArchive = 'a3d8834fae7c986033e72db669239cd9c1cedc96'

[phases.install]
cmds = ['bun i']
paths = ['/app/node_modules/.bin']
dependsOn = ['setup']
cacheDirectories = ['/root/.bun']

[phases.build]
cmds = ['bun run --cwd "apps/next" build']
dependsOn = ['install']
cacheDirectories = ['apps/next/.next/cache', 'node_modules/.cache']

[start]
cmd = 'bun run --cwd "apps/next" start'
_typedev
_typedev11mo ago
Amazing! Doing a write up right now
Solution
_typedev
_typedev11mo ago
First of all thanks @Brody ! For anyone currently working with Bun/Next.js/Railway this might be helpful: For me , builds with next.js kept failing, and I’ve tried everything a lot of different methods, and configurations What worked was Brody’s solution to separate the nixplan from the railway.config into a nixpack.config "nixpacksConfigPath": "apps/next/nixpacks.toml"
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"watchPatterns": ["apps/next/**"],
"nixpacksConfigPath": "apps/next/nixpacks.toml"
},
"deploy": {
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"watchPatterns": ["apps/next/**"],
"nixpacksConfigPath": "apps/next/nixpacks.toml"
},
"deploy": {
"numReplicas": 1,
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
buildImage = 'ghcr.io/railwayapp/nixpacks:ubuntu-1697500996'

[variables]
CI = 'true'
NODE_ENV = 'production'
NIXPACKS_METADATA = 'node'
NIXPACKS_NO_CACHE = '1'
NPM_CONFIG_PRODUCTION = 'false'

[phases.setup]
nixPkgs = ['nodejs_20', 'bun']
nixOverlays = ['https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz']
nixpkgsArchive = 'a3d8834fae7c986033e72db669239cd9c1cedc96'

[phases.install]
cmds = ['bun i']
paths = ['/app/node_modules/.bin']
dependsOn = ['setup']
cacheDirectories = ['/root/.bun']

[phases.build]
cmds = ['bun run --cwd "apps/next" build']
dependsOn = ['install']
cacheDirectories = ['apps/next/.next/cache', 'node_modules/.cache']

[start]
cmd = 'bun run --cwd "apps/next" start'
buildImage = 'ghcr.io/railwayapp/nixpacks:ubuntu-1697500996'

[variables]
CI = 'true'
NODE_ENV = 'production'
NIXPACKS_METADATA = 'node'
NIXPACKS_NO_CACHE = '1'
NPM_CONFIG_PRODUCTION = 'false'

[phases.setup]
nixPkgs = ['nodejs_20', 'bun']
nixOverlays = ['https://github.com/railwayapp/nix-npm-overlay/archive/main.tar.gz']
nixpkgsArchive = 'a3d8834fae7c986033e72db669239cd9c1cedc96'

[phases.install]
cmds = ['bun i']
paths = ['/app/node_modules/.bin']
dependsOn = ['setup']
cacheDirectories = ['/root/.bun']

[phases.build]
cmds = ['bun run --cwd "apps/next" build']
dependsOn = ['install']
cacheDirectories = ['apps/next/.next/cache', 'node_modules/.cache']

[start]
cmd = 'bun run --cwd "apps/next" start'
Notes: passing in :nodejs_20 so builds work with next.js 14.0 Using the cmd bun run --cwd "apps/next" build to path to the directory and then build from there. This will correctly link packages workspace:* If builds are failing you might want to clean your bun.lockb from the root of your project rm -f bun.lockb then bun i Successfully deploys 14 with bun 1.0.7
Brody
Brody11mo ago
happy to help 🙂
Want results from more Discord servers?
Add your server