R
Railway2mo ago
rpuls

Need help configuring nickspacks

Hi, I want the following to happen, npm install npm run build npm run init npm run start This is my nickspacks file:
[phases.setup]
node_version = "22.5.1"

[phases.install]
cmds = [
"npm install -g corepack",
"corepack enable",
"corepack prepare [email protected] --activate",
"npm install"
]

[phases.build]
cmds = [
"npm run build"
]

[phases.start]
cmds = [
"npm run init",
"npm run start"
]
[phases.setup]
node_version = "22.5.1"

[phases.install]
cmds = [
"npm install -g corepack",
"corepack enable",
"corepack prepare [email protected] --activate",
"npm install"
]

[phases.build]
cmds = [
"npm run build"
]

[phases.start]
cmds = [
"npm run init",
"npm run start"
]
But when I deploy, the nickspacks plan looks like this: ╔═════════ Nixpacks v1.29.0 ══════════╗ ║ setup │ nodejs_22, yarn-1_x ║ ║─────────────────────────────────────║ ║ start │ npm run init ║ ║ │ npm run start ║ ║─────────────────────────────────────║ ║ install │ npm install -g corepack ║ ║ │ corepack enable ║ ║ │ corepack prepare [email protected] --activate║ ║ │ npm install ║ ║──────────────────────────────────────║ ║ build │ npm run build ║ ║──────────────────────────────────────║ ║ start │ yarn run start ║ ╚═══════════════════════════════╝ I have not set a custom start command - why does it put my start commands before install? - where does the last yarn command come from? Because of the order of things my project doesn build correctly, so how can I get the order right?
Solution:
[start]
cmd = "npm run init && npm run start"
[start]
cmd = "npm run init && npm run start"
thats all you need, nixpacks will run npm ci and npm build in the correct order by default...
Jump to solution
20 Replies
Percy
Percy2mo ago
Project ID: c13d3629-3ab7-4743-994f-b90b613ce66e
rpuls
rpulsOP2mo ago
c13d3629-3ab7-4743-994f-b90b613ce66e
Brody
Brody2mo ago
did you use AI to generate that nixpacks.toml file?
rpuls
rpulsOP2mo ago
Yes, partially. But i tried like 10 different formats now, none of which gave me the desired results.
Brody
Brody2mo ago
yeah you have some syntax wrong, and have left some syntax out why npm install instead of npm ci?
rpuls
rpulsOP2mo ago
I have used this part
providers = ["node"]

[phases.install]
cmds = [
"npm install -g corepack",
"corepack enable",
"corepack prepare [email protected] --activate",
"npm install"
]
providers = ["node"]

[phases.install]
cmds = [
"npm install -g corepack",
"corepack enable",
"corepack prepare [email protected] --activate",
"npm install"
]
for ages, and it works well. But I want to add custom build and start command to the nixpacks file (if possible). What does npm ci do ?
Brody
Brody2mo ago
installs packages from the lock file
rpuls
rpulsOP2mo ago
Oh. I thought it already did that 🤔😬
Brody
Brody2mo ago
does node 22 not come with npm 10? is there any reason you are installing npm with corepack?
rpuls
rpulsOP2mo ago
I will try without it, but i recall resolving some error with this... but thats long ago, and a lot have changed since, so my config might be outdated in that regard. Anyway, my editor doesn't know nickspacks syntax, can't highlight whats wrong. is cmd = "npm run x && npm run y" better than cmds = [] ?
Brody
Brody2mo ago
cmd is only valid syntax for the start phase ill rewrite this for you, gimmie a few minutes i assume this is the order you want?
npm install
npm run build
npm run init
npm run start
npm install
npm run build
npm run init
npm run start
rpuls
rpulsOP2mo ago
That's right. And I assume the run init and run start must happen during the start phase - if that is important
Brody
Brody2mo ago
if you want them to run during runtime sure
Solution
Brody
Brody2mo ago
[start]
cmd = "npm run init && npm run start"
[start]
cmd = "npm run init && npm run start"
thats all you need, nixpacks will run npm ci and npm build in the correct order by default
rpuls
rpulsOP2mo ago
Alright, so I delete evrything else? I think though, that it will pick node 18 then? and not 22 ?
Brody
Brody2mo ago
the node version is picked up from engines.node in your package.json
rpuls
rpulsOP2mo ago
OK, should be good then for this project
╔═════════════ Nixpacks v1.29.0 ═════════════╗

║ setup │ nodejs_22, yarn-1_x ║

║────────────────────────────────────────────║

║ install │ yarn install --check-cache ║

║────────────────────────────────────────────║

║ build │ yarn run build ║

║────────────────────────────────────────────║

║ start │ npm run init && npm run start ║

╚════════════════════════════════════════════╝
╔═════════════ Nixpacks v1.29.0 ═════════════╗

║ setup │ nodejs_22, yarn-1_x ║

║────────────────────────────────────────────║

║ install │ yarn install --check-cache ║

║────────────────────────────────────────────║

║ build │ yarn run build ║

║────────────────────────────────────────────║

║ start │ npm run init && npm run start ║

╚════════════════════════════════════════════╝
Alright, this looks better! So, if I just delete yarn.lock it will default to npm ci ? 🙂
Brody
Brody2mo ago
correct
rpuls
rpulsOP2mo ago
Alright. Thanks Brody! Always appreciate your rapid help 🙂
Brody
Brody2mo ago
no problem!
Want results from more Discord servers?
Add your server