Why doesn't Fly.io install any dependency from `devDependency`?

Hello,

I tried Fly.io the first time to deploy my Node.js app and I got errors like tsc is not found and you need to install node types even though I had typescript and @types/node in my devDependencies so the only solution that worked for me is I had to move all my dependecies from devDependencies to dependencies so it can work.

Isn’t there any fix to this?

What does your Dockerfile look like?

FROM debian:bullseye as builder

ARG NODE_VERSION=16.13.2
ARG YARN_VERSION=1.22.17

RUN apt-get update; apt install -y curl
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
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" ]

Note the comment:

# to install all modules: "yarn install --production=false"

The line you want to modify is:

RUN yarn install && yarn run build

1 Like

I did not read any of that, I never thought it would explained a comment. Thank you very much for your help.