Need help configuring nickspacks

10 months ago

Hi, I want the following to happen,

npm install
npm run build
npm run init
npm run start

This is my nickspacks file:

node_version = "22.5.1"

[phases.install]
cmds = [
  "npm install -g corepack",
  "corepack enable",
  "corepack prepare npm@10.8.2 --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 │ nodejs22, yarn-1x ║

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

║ start │ npm run init ║

║ │ npm run start ║

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

║ install │ npm install -g corepack ║

║ │ corepack enable ║

║ │ corepack prepare npm@10.8.2 --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?

0 Replies

10 months ago

c13d3629-3ab7-4743-994f-b90b613ce66e


10 months ago

did you use AI to generate that nixpacks.toml file?


10 months ago

Yes, partially. But i tried like 10 different formats now, none of which gave me the desired results.


10 months ago

yeah you have some syntax wrong, and have left some syntax out


10 months ago

why npm install instead of npm ci?


10 months ago

I have used this part ```providers = ["node"]

[phases.install]
cmds = [
"npm install -g corepack",
"corepack enable",
"corepack prepare npm@10.8.2 --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 ?


10 months ago

installs packages from the lock file


10 months ago

Oh. I thought it already did that 🤔😬


10 months ago

does node 22 not come with npm 10? is there any reason you are installing npm with corepack?


10 months 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 = [] ?


10 months ago

cmd is only valid syntax for the start phase


10 months ago

ill rewrite this for you, gimmie a few minutes


10 months ago

i assume this is the order you want?

npm install
npm run build
npm run init
npm run start

10 months ago

That's right. And I assume the run init and run start must happen during the start phase - if that is important


10 months ago

if you want them to run during runtime sure


10 months ago

[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


10 months ago

Alright, so I delete evrything else? I think though, that it will pick node 18 then? and not 22 ?


10 months ago

the node version is picked up from engines.node in your package.json


10 months ago

OK, should be good then for this project


10 months ago

```

╔═════════════ Nixpacks v1.29.0 ═════════════╗

║ setup │ nodejs22, yarn-1x ║

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

║ 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 ? 🙂


10 months ago

correct


10 months ago

Alright. Thanks Brody! Always appreciate your rapid help 🙂


10 months ago

no problem!