Cannot launch or deploy new NestJS app

I’m testing out a newly skeleton app which builds just fine locally.
I’ve tried changing the npm script to use npx, as i feared it might be a global npm package issue, but that didnt help either. help?

Running flyctl launch or flyctl deploy both results in the following error:

flyctl launch
An existing fly.toml file was found for app middleware
App is not running, deploy...
==> Building image
Remote builder fly-builder-spring-field-8952 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon  138.2kB
[+] Building 21.7s (11/15)
 => CACHED [internal] load remote build context                                                                                                 0.0s
 => CACHED copy /context /                                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/debian:bullseye                                                                              1.7s
 => CACHED [builder 1/9] FROM docker.io/library/debian:bullseye@sha256:534da5794e770279c889daa891f46f5a530b0c5de8bfbc5e40394a0164d9fa87         0.0s
 => CACHED [builder 2/9] RUN apt-get update; apt install -y curl python-is-python3 pkg-config build-essential                                   0.0s
 => CACHED [builder 3/9] RUN curl https://get.volta.sh | bash                                                                                   0.0s
 => CACHED [builder 4/9] RUN volta install node@19.4.0 yarn@1.22.19                                                                             0.0s
 => CACHED [builder 5/9] RUN mkdir /app                                                                                                         0.0s
 => CACHED [builder 6/9] WORKDIR /app                                                                                                           0.0s
 => CACHED [builder 7/9] COPY . .                                                                                                               0.0s
 => ERROR [builder 8/9] RUN yarn install && yarn run build                                                                                     20.1s
------
 > [builder 8/9] RUN yarn install && yarn run build:
#11 0.551 yarn install v1.22.19
#11 0.626 [1/4] Resolving packages...
#11 0.889 [2/4] Fetching packages...
#11 15.74 [3/4] Linking dependencies...
#11 15.75 warning " > apollo-server-express@3.11.1" has unmet peer dependency "express@^4.17.1".
#11 15.75 warning " > ts-loader@9.4.2" has unmet peer dependency "webpack@^5.0.0".
#11 17.48 [4/4] Building fresh packages...
#11 17.80 Done in 17.26s.
#11 17.99 yarn run v1.22.19
#11 18.02 $ npx nest build
#11 19.77 npm notice
#11 19.78 npm notice New minor version of npm available! 9.2.0 -> 9.3.0
#11 19.78 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.3.0>
#11 19.78 npm notice Run `npm install -g npm@9.3.0` to update!
#11 19.78 npm notice
#11 19.78 npm ERR! could not determine executable to run
#11 19.78
#11 19.78 npm ERR! A complete log of this run can be found in:
#11 19.78 npm ERR!     /root/.npm/_logs/2023-01-17T10_43_28_399Z-debug-0.log
#11 19.80 error Command failed with exit code 1.
#11 19.80 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c yarn install && yarn run build]: exit code: 1

If it builds locally, a good first troubleshooting step could be using the --local-only flag when running fly deploy. That would use your local Docker installation to build the image.

Do you have a sample .Dockerfile that you could share?

FROM debian:bullseye as builder

ARG NODE_VERSION=19.4.0
ARG YARN_VERSION=1.22.19

RUN apt-get update; apt install -y curl python-is-python3 pkg-config build-essential
RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME /root/.volta
ENV PATH /root/.volta/bin:$PATH
RUN volta install node@${NODE_VERSION} yarn@${YARN_VERSION}

#######################################################################

RUN mkdir /app
WORKDIR /app

# Yarn will not install any package listed in "devDependencies" when NODE_ENV is set to "production"
# to install all modules: "yarn install --production=false"
# Ref: https://classic.yarnpkg.com/lang/en/docs/cli/install/#toc-yarn-install-production-true-false

ENV NODE_ENV production

COPY . .

RUN yarn install && yarn run build
RUN yarn global add @nestjs/cli
FROM debian:bullseye

LABEL fly_launch_runtime="nodejs"

COPY --from=builder /root/.volta /root/.volta
COPY --from=builder /app /app

WORKDIR /app
ENV NODE_ENV production
ENV PATH /root/.volta/bin:$PATH

CMD [ "yarn", "run", "start" ]

See above :slight_smile:

What does /root/.npm/_logs/2023-01-17T10_43_28_399Z-debug-0.log look like?

I’m not exactly sure how to check that.
flyctl logs just hangs, and running the broken command while observing the hanging flyctl logs also produces no output.

sorry if this is noobish !

No worries. I’m trying to do a test deploy. Do you have a sample project I could get from somewhere? I need something to copy into /app for the build to proceed.

You know what, in the end turns out the problem was that the devdependencies werent being installed because it set production as a node env. changing that fixed my build issue. :slight_smile:

Still, i’d love to understand how to inspect those log files.
Any tips on that?

See above again :slight_smile: