R
Railwayā€¢3y ago
federaco

NestJS Build Error

Hi, I created a Railway project with a NestJS API and a Postgres DB, it was working fine, but after a while I wanted to create a second project so I can have a test environment, I followed the same setup steps of the working project, but I can't get it working. The project was generated with the nest cli. The start command for the API is "npm install && npm run start:prod" I created an Empty Service in Railway I'm getting this error:

#11 2.235 npm ERR! code EUSAGE

#11 2.239 npm ERR!
#11 2.239 npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
#11 2.239 npm ERR!
#11 2.239 npm ERR! Missing: [email protected] from lock file
#11 2.239 npm ERR! Missing: [email protected] from lock file
#11 2.239 npm ERR! Missing: [email protected] from lock file
#11 2.239 npm ERR!
#11 2.239 npm ERR! Clean install a project
#11 2.239 npm ERR!
#11 2.239 npm ERR! Usage:
#11 2.239 npm ERR! npm ci
#11 2.239 npm ERR!
#11 2.239 npm ERR! Options:
#11 2.239 npm ERR! [--no-audit] [--foreground-scripts] [--ignore-scripts]
#11 2.239 npm ERR! [--script-shell <script-shell>]
#11 2.239 npm ERR!
#11 2.239 npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
#11 2.240 npm ERR!
#11 2.240 npm ERR! Run "npm help ci" for more info
#11 2.242

#11 2.242 npm ERR! A complete log of this run can be found in:
#11 2.242 npm ERR! /root/.npm/_logs/2022-09-24T23_56_10_362Z-debug-0.log
#11 ERROR: executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1
-----
> [stage-0 7/9] RUN --mount=type=cache,id=s/ca773b95-199f-4c52-94bc-3d867b679908-/root/npm,target=/root/.npm npm ci:
-----
executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1

Error: Docker build failed

#11 2.235 npm ERR! code EUSAGE

#11 2.239 npm ERR!
#11 2.239 npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
#11 2.239 npm ERR!
#11 2.239 npm ERR! Missing: [email protected] from lock file
#11 2.239 npm ERR! Missing: [email protected] from lock file
#11 2.239 npm ERR! Missing: [email protected] from lock file
#11 2.239 npm ERR!
#11 2.239 npm ERR! Clean install a project
#11 2.239 npm ERR!
#11 2.239 npm ERR! Usage:
#11 2.239 npm ERR! npm ci
#11 2.239 npm ERR!
#11 2.239 npm ERR! Options:
#11 2.239 npm ERR! [--no-audit] [--foreground-scripts] [--ignore-scripts]
#11 2.239 npm ERR! [--script-shell <script-shell>]
#11 2.239 npm ERR!
#11 2.239 npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
#11 2.240 npm ERR!
#11 2.240 npm ERR! Run "npm help ci" for more info
#11 2.242

#11 2.242 npm ERR! A complete log of this run can be found in:
#11 2.242 npm ERR! /root/.npm/_logs/2022-09-24T23_56_10_362Z-debug-0.log
#11 ERROR: executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1
-----
> [stage-0 7/9] RUN --mount=type=cache,id=s/ca773b95-199f-4c52-94bc-3d867b679908-/root/npm,target=/root/.npm npm ci:
-----
executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1

Error: Docker build failed
Thanks community!
26 Replies
nebula
nebulaā€¢3y ago
send package.json
federaco
federacoOPā€¢3y ago
There it is. Thank you!
Rumon
Rumonā€¢3y ago
Try the following on Railway UI: Build Command: npm run build Start Command: npm run start:prod
federaco
federacoOPā€¢3y ago
Thanks for the response. I just tried it and I got the same error šŸ˜• Hi neb!, sorry to bother you, I sent you my package.json, it looks you have an idea about solving this error, can you share it?, so I can try it?, thank you very much!
federaco
federacoOPā€¢3y ago
I just created a new NestJS project, and put it into a public repo, used that repo to build in Railway, and I'm still getting the (kind of) same error:
#8 [4/4] RUN npm run build
#8 sha256:2217b003228b75aae7ee4c8dedf164373c980810992dfd322ee273fd092d4bff

#8 0.425 /bin/bash: line 1: npm: command not found
#8 ERROR: executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127
-----
> [4/4] RUN npm run build:
-----
executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127

Error: Docker build failed
#8 [4/4] RUN npm run build
#8 sha256:2217b003228b75aae7ee4c8dedf164373c980810992dfd322ee273fd092d4bff

#8 0.425 /bin/bash: line 1: npm: command not found
#8 ERROR: executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127
-----
> [4/4] RUN npm run build:
-----
executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127

Error: Docker build failed
This is the repo: https://github.com/federicopenaranda/nestjs-railway It looks like my project code is not the problem, because I just generated a new NestJS project and didn't add any new feature or library. Thanks for all the help.
GitHub
GitHub - federicopenaranda/nestjs-railway: Test nestjs build in rai...
Test nestjs build in railway. Contribute to federicopenaranda/nestjs-railway development by creating an account on GitHub.
nebula
nebulaā€¢3y ago
can you send the entire logfile
federaco
federacoOPā€¢3y ago
Sure:
==============
Using Nixpacks
==============

ā•”ā•ā•ā•ā•ā•ā•ā•ā• Nixpacks v0.9.0 ā•ā•ā•ā•ā•ā•ā•ā•ā•—
ā•‘ build ā”‚ npm run build ā•‘
ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘
ā•‘ start ā”‚ npm run start:prod ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•


#1 [internal] load build definition from Dockerfile
#1 sha256:36493a9c8cd43ec4c0686cec3ddf684e2a64f5f343f26b4e98ab3ba66bbf636b
#1 transferring dockerfile: 1.18kB done
#1 DONE 0.1s

#2 [internal] load .dockerignore
#2 sha256:4563847ef7b248e624485e2c63a65bd8d867a82089908af4b13ae9fb5035316e

#2 transferring context: 2B done
#2 DONE 0.1s


#3 [internal] load metadata for ghcr.io/railwayapp/nixpacks:debian-1664237509
#3 sha256:14654d6ad0ab90f84b1d5bb7e36d9fe0da64cb0dce7f66299caee27917d0e4b3

#3 DONE 0.2s


#4 [stage-0 1/11] FROM ghcr.io/railwayapp/nixpacks:debian-1664237509@sha256:b9d126f523701b3c9e6629706f2129990b21f731e3091fe579207cd4805fa27d
#4 sha256:e6e39311ac6d3f89532fa59c41fc892def134eb3f4b0f5af71ce50ddd618cfcb
#4 DONE 0.0s

#5 [stage-0 2/11] WORKDIR /app/
#5 sha256:17c3ef9792c541c82fadcc87ddae9be2606103ef7a3fa9bdd701b9e786361f83
#5 CACHED

#6 [internal] load build context
#6 sha256:f23ed8d63423c145a2a3f9432fe1ecb2889f08564d83e44bcfbcb75faf2c80dc
#6 transferring context: 575.51kB done
#6 DONE 0.1s


#7 [3/4] COPY . /app/
#7 sha256:a97833c6270af3d00cceac5c4be9d87e79e04072418738ffc559595dc1cf5afb

#7 DONE 0.1s

#8 [4/4] RUN npm run build
#8 sha256:2217b003228b75aae7ee4c8dedf164373c980810992dfd322ee273fd092d4bff

#8 0.425 /bin/bash: line 1: npm: command not found
#8 ERROR: executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127
-----
> [4/4] RUN npm run build:
-----
executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127

Error: Docker build failed
==============
Using Nixpacks
==============

ā•”ā•ā•ā•ā•ā•ā•ā•ā• Nixpacks v0.9.0 ā•ā•ā•ā•ā•ā•ā•ā•ā•—
ā•‘ build ā”‚ npm run build ā•‘
ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘
ā•‘ start ā”‚ npm run start:prod ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•


#1 [internal] load build definition from Dockerfile
#1 sha256:36493a9c8cd43ec4c0686cec3ddf684e2a64f5f343f26b4e98ab3ba66bbf636b
#1 transferring dockerfile: 1.18kB done
#1 DONE 0.1s

#2 [internal] load .dockerignore
#2 sha256:4563847ef7b248e624485e2c63a65bd8d867a82089908af4b13ae9fb5035316e

#2 transferring context: 2B done
#2 DONE 0.1s


#3 [internal] load metadata for ghcr.io/railwayapp/nixpacks:debian-1664237509
#3 sha256:14654d6ad0ab90f84b1d5bb7e36d9fe0da64cb0dce7f66299caee27917d0e4b3

#3 DONE 0.2s


#4 [stage-0 1/11] FROM ghcr.io/railwayapp/nixpacks:debian-1664237509@sha256:b9d126f523701b3c9e6629706f2129990b21f731e3091fe579207cd4805fa27d
#4 sha256:e6e39311ac6d3f89532fa59c41fc892def134eb3f4b0f5af71ce50ddd618cfcb
#4 DONE 0.0s

#5 [stage-0 2/11] WORKDIR /app/
#5 sha256:17c3ef9792c541c82fadcc87ddae9be2606103ef7a3fa9bdd701b9e786361f83
#5 CACHED

#6 [internal] load build context
#6 sha256:f23ed8d63423c145a2a3f9432fe1ecb2889f08564d83e44bcfbcb75faf2c80dc
#6 transferring context: 575.51kB done
#6 DONE 0.1s


#7 [3/4] COPY . /app/
#7 sha256:a97833c6270af3d00cceac5c4be9d87e79e04072418738ffc559595dc1cf5afb

#7 DONE 0.1s

#8 [4/4] RUN npm run build
#8 sha256:2217b003228b75aae7ee4c8dedf164373c980810992dfd322ee273fd092d4bff

#8 0.425 /bin/bash: line 1: npm: command not found
#8 ERROR: executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127
-----
> [4/4] RUN npm run build:
-----
executor failed running [/bin/bash -ol pipefail -c npm run build]: exit code: 127

Error: Docker build failed
nebula
nebulaā€¢3y ago
okay have you set a start and build command manually?
federaco
federacoOPā€¢3y ago
yes, build command:
npm run build
npm run build
, start command:
npm run start:prod
npm run start:prod
nebula
nebulaā€¢3y ago
you should remove those from railway
federaco
federacoOPā€¢3y ago
I should leave them blank?
nebula
nebulaā€¢3y ago
yes
federaco
federacoOPā€¢3y ago
let me try.. neb, I tried and it built successfully!, but then I tried again with the commands I wrote manually, and it worked too!!!, I don't know why this is happening. Anyway, I tried in my original project (the one I got the error in the first place) and I'm getting the same error as before:
#12 [stage-0 8/10] RUN --mount=type=cache,id=s/ca773b95-199f-4c52-94bc-3d867b679908-/root/npm,target=/root/.npm npm ci

#12 sha256:78abb8d0f5f6bfc16201979e02eae7fbd4865a0452eefdd5f0664ad196c546de

#12 0.868 npm
WARN config production Use `--omit=dev` instead.

#12 2.108 npm ERR! code EUSAGE
#12 2.112 npm ERR!
#12 2.112 npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
#12 2.112 npm ERR!
#12 2.112 npm ERR! Missing: [email protected] from lock file
#12 2.112 npm ERR! Missing: [email protected] from lock file
#12 2.112 npm ERR! Missing: [email protected] from lock file
#12 2.112 npm ERR!
#12 2.112 npm ERR! Clean install a project
#12 2.112 npm ERR!
#12 2.112 npm ERR! Usage:
#12 2.112 npm ERR! npm ci
#12 2.112 npm ERR!
#12 2.112 npm ERR! Options:
#12 2.112 npm ERR! [--no-audit] [--foreground-scripts] [--ignore-scripts]
#12 2.112 npm ERR! [--script-shell <script-shell>]
#12 2.112 npm ERR!
#12 2.112 npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
#12 2.112 npm ERR!
#12 2.113 npm ERR! Run "npm help ci" for more info
#12 2.114
#12 2.115 npm ERR! A complete log of this run can be found in:
#12 2.115 npm ERR! /root/.npm/_logs/2022-10-01T13_53_37_860Z-debug-0.log

#12 ERROR: executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1
-----
> [stage-0 8/10] RUN --mount=type=cache,id=s/ca773b95-199f-4c52-94bc-3d867b679908-/root/npm,target=/root/.npm npm ci:
-----

executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1

Error: Docker build failed
#12 [stage-0 8/10] RUN --mount=type=cache,id=s/ca773b95-199f-4c52-94bc-3d867b679908-/root/npm,target=/root/.npm npm ci

#12 sha256:78abb8d0f5f6bfc16201979e02eae7fbd4865a0452eefdd5f0664ad196c546de

#12 0.868 npm
WARN config production Use `--omit=dev` instead.

#12 2.108 npm ERR! code EUSAGE
#12 2.112 npm ERR!
#12 2.112 npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
#12 2.112 npm ERR!
#12 2.112 npm ERR! Missing: [email protected] from lock file
#12 2.112 npm ERR! Missing: [email protected] from lock file
#12 2.112 npm ERR! Missing: [email protected] from lock file
#12 2.112 npm ERR!
#12 2.112 npm ERR! Clean install a project
#12 2.112 npm ERR!
#12 2.112 npm ERR! Usage:
#12 2.112 npm ERR! npm ci
#12 2.112 npm ERR!
#12 2.112 npm ERR! Options:
#12 2.112 npm ERR! [--no-audit] [--foreground-scripts] [--ignore-scripts]
#12 2.112 npm ERR! [--script-shell <script-shell>]
#12 2.112 npm ERR!
#12 2.112 npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
#12 2.112 npm ERR!
#12 2.113 npm ERR! Run "npm help ci" for more info
#12 2.114
#12 2.115 npm ERR! A complete log of this run can be found in:
#12 2.115 npm ERR! /root/.npm/_logs/2022-10-01T13_53_37_860Z-debug-0.log

#12 ERROR: executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1
-----
> [stage-0 8/10] RUN --mount=type=cache,id=s/ca773b95-199f-4c52-94bc-3d867b679908-/root/npm,target=/root/.npm npm ci:
-----

executor failed running [/bin/bash -ol pipefail -c npm ci]: exit code: 1

Error: Docker build failed
nebula
nebulaā€¢3y ago
yeah thats a different error
federaco
federacoOPā€¢3y ago
I tried with the blank build and start commands there šŸ‘†
nebula
nebulaā€¢3y ago
to fix it run npm i locally and commit it
federaco
federacoOPā€¢3y ago
ok, trying....
npm i
npm i
install all packages, but node_modules folder is in .gitignore file, so there is nothing to commit šŸ¤”
nebula
nebulaā€¢3y ago
remove package-lock.json from gitignore
federaco
federacoOPā€¢3y ago
nothing, same error, I'm trying with and without build/start commands
jr
jrā€¢3y ago
The problem here is that we did not detect that it is a Node app since the package.json file is nested within the railway/ directory The problem here is that the lockfile is out of date with the package.json file which should be resolved locally before building for production. You can run npm i and then commit the changes in the lockfile Do you have a project id?
federaco
federacoOPā€¢3y ago
yes, I'm using a single repo for frontend and backend, that's why I have nested node apps (one is in Angular and the backend is in NestJS), but I thought that specifying the Root Directory in settings would fix that issue. This is the project id?: overconfident-milk Or this one?: 42798527-bf72-4257-95f1-b3e4cdc0ef0a/service/ca773b95-199f-4c52-94bc-3d867b679908
Agam
Agamā€¢3y ago
This one, yeah The ca77*** thing
federaco
federacoOPā€¢3y ago
ohh, ok
Agam
Agamā€¢3y ago
Well actually you can easily get from project settings and under general tab (as we have already got the Id, wont continue this topic)
jr
jrā€¢3y ago
I thought that specifying the Root Directory in settings would fix that issue.
It did fix the Node not detected issue. The new issue is that the lockfile is out of date. If you don't care about that you can set the NIXPACKS_INSTALL_CMD=npm i and it will install without checking the lockfile Also it is using the lockfile in the root directory not at the repo root
federaco
federacoOPā€¢3y ago
ok, thanks where should I put the "NIXPACKS_INSTALL_CMD=npm i" command? nevermind, in the Variables tab! the NIXPACKS_INSTALL_CMD variable fixed the issue!, thank you very much!
Want results from more Discord servers?
Add your server