ENOENT on NodeJS pool supervisor (LiveSvelte)

Hello, all! Hope you are doing well.

Unfortunately, I’ve been having a bit of trouble with running a LiveSvelte app. When the Dockerfile’s CMD is `CMD [“app/bin/server”] and I check the logs, I see the following error:

mad [info]Kernel pid terminated (application_controller) ({application_start_failure,casa_do_caminho,{{shutdown,{failed_to_start_child,'Elixir.NodeJS.Supervisor',{shutdown,{failed_to_start_child,'Elixir.NodeJS.Supervisor.Pool',{{badmatch,{error,{enoent,[{erlang,open_port,[{spawn_executable,nil},[{line,65536},{env,[{"NODE_PATH","/app/lib/casa_do_caminho-0.1.0/priv/svelte:/app/lib/casa_do_caminho-0.1.0/priv/svelte/node_modules"},{"WRITE_CHUNK_SIZE","65536"}]},{args,[<<"/app/lib/nodejs-2.0.0/priv/server.js">>]}]],[{error_info,#{module => erl_erts_errors}}]},{'Elixir.NodeJS.Worker',init,1,[{file,"lib/nodejs/worker.ex"},{line,51}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,423}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,390}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}}},[{poolboy,new_worker,1,[{file,"/app/deps/poolboy/src/poolboy.erl"},{line,283}]},{poolboy,prepopulate,3,[{file,"/app/deps/poolboy/src/poolboy.erl"},{line,304}]},{poolboy,init,3,[{file,"/app/deps/poolboy/src/pool

I am not entirely sure of the cause, but I imagine one of three things is missing:

  1. NodeJS
  2. The JS file to run in the destination directory
  3. node_modules in the destination directory

Now, I have tried a few things to either diagnose or fix the problem, but to no avail. I’ve tried changing the NODE_PATH env variable’s content to be

/root/.nvm/versions/node/v${NODE_VERSION}/lib/node_modules

or

/root/.nvm/versions/node/v${NODE_VERSION}/bin

and even

/root/.nvm/versions/node/v${NODE_VERSION}/bin/node

but none worked. I can confirm that the JS file to be run in the directory is present and, weirdly enough, by setting the Dockerfile’s final CMD to be CMD ["sleep", "infinity"], I can fly ssh console into the instance and manually start /app/bin/server with no problems whatsoever, and have verified that the app is available once the command runs. My Dockerfile is available below - I appreciate the help, and thank you in advance.

# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
# instead of Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
# This file is based on these images:
#
#   - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
#   - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20240513-slim - for the release image
#   - https://pkgs.org/ - resource for finding needed packages
#   - Ex: hexpm/elixir:1.16.2-erlang-24.3.4.17-debian-bullseye-20240513-slim
#
ARG ELIXIR_VERSION=1.16.2
ARG OTP_VERSION=24.3.4.17
ARG DEBIAN_VERSION=bullseye-20240513-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
    && apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

ENV NODE_VERSION=20.11.0
ENV NVM_VERSION=0.39.7
RUN apt update && apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

COPY priv priv

COPY lib lib

COPY assets assets

# compile assets
RUN mix assets.deploy

# Compile the release
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && \
  apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*

ENV NODE_VERSION=20.11.0
ENV NVM_VERSION=0.39.7
RUN apt update && apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
ENV NODE_PATH="/root/.nvm/versions/node/v${NODE_VERSION}/lib/node_modules"
RUN node --version
RUN npm --version

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

WORKDIR "/app"
RUN chown nobody /app

# set runner ENV
ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/casa_do_caminho ./

USER nobody

# If using an environment that doesn't automatically reap zombie processes, it is
# advised to add an init process such as tini via `apt-get install`
# above and adding an entrypoint. See https://github.com/krallin/tini for details
# ENTRYPOINT ["/tini", "--"]

CMD ["/app/bin/server"]
# CMD ["sleep", "infinity"]

Apologies for the long post, and many thanks!