Need help configuring nickspacks

a year 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?

23 Replies

a year ago

c13d3629-3ab7-4743-994f-b90b613ce66e


a year ago

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


a year ago

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


a year ago

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


a year ago

why npm install instead of npm ci?


a year 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 ?


a year ago

installs packages from the lock file


a year ago

Oh. I thought it already did that 🤔😬


a year ago

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


a year 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 = [] ?


a year ago

cmd is only valid syntax for the start phase


a year ago

ill rewrite this for you, gimmie a few minutes


a year ago

i assume this is the order you want?

npm install
npm run build
npm run init
npm run start

a year ago

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


a year ago

if you want them to run during runtime sure


a year 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


a year ago

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


a year ago

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


a year ago

OK, should be good then for this project


a year 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 ? 🙂


a year ago

correct


a year ago

Alright. Thanks Brody! Always appreciate your rapid help 🙂


a year ago

no problem!


Loading...