Need help configuring nickspacks

2 years 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 │ nodejs_22, yarn-1_x ║

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

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

Closed

23 Replies

2 years ago

c13d3629-3ab7-4743-994f-b90b613ce66e


2 years ago

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


2 years ago

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


2 years ago

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


2 years ago

why npm install instead of npm ci?


2 years 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"

]


But I want to add custom build and start command to the nixpacks file (if possible).

What does `npm ci` do ?


2 years ago

installs packages from the lock file


2 years ago

Oh. I thought it already did that 🤔😬


2 years ago

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


2 years 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 = [] ?


2 years ago

cmd is only valid syntax for the start phase


2 years ago

ill rewrite this for you, gimmie a few minutes


2 years ago

i assume this is the order you want?

npm install
npm run build
npm run init
npm run start

2 years ago

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


2 years ago

if you want them to run during runtime sure


2 years 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


2 years ago

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


2 years ago

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


2 years ago

OK, should be good then for this project


2 years ago


╔═════════════ 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 ? 🙂


2 years ago

correct


2 years ago

Alright. Thanks Brody! Always appreciate your rapid help 🙂


2 years ago

no problem!


Welcome!

Sign in to your Railway account to join the conversation.

Loading...