I simply start a new phoenix project and when I try to run it, I receive this error:
[error] Could not start Node.js watcher because script
"/home/username/projects/Elixir/projectName/assets/node_modules/webpack/bin/webpack.js"
does not exist. Your Phoenix application is still running,
however assets won't be compiled. You may fix this by
running "npm install" inside the "assets" directory.
I think the current JavaScript dependencies in a default phoenix project are only compatible with node <15. You can use nvm to manage your node version (similar to asdf for elixir and erlang).
Oh cool, always good to have fewer tools on the go. I’m working full-time in a php backend + laravel frontend app so my Elixir ecosystem knowledge is hobby level only.
# set the base image to Debian
# https://hub.docker.com/_/debian/
FROM debian:latest
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
&& apt-get install -y curl \
&& apt-get -y autoclean
# nvm environment variables
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 4.4.7
# install nvm
# https://github.com/creationix/nvm#install-script
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash
# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# confirm installation
RUN node -v
RUN npm -v
This is the docker image I am using at the moment for a phoenix app based on the one in the phoenix docs. You can specify the versions of the dependencies with apk like this apk add npm=7:
# install build dependencies
RUN apk add --no-cache build-base npm git python3
# 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 ./
COPY config config
RUN mix do deps.get, deps.compile
# fix another broken dependency 25/5/2021
RUN mix do deps.clean cowlib, deps.get cowlib, deps.compile cowlib
# build assets
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
COPY priv priv
COPY assets assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest
# compile and build release
COPY lib lib
# uncomment COPY if rel/ exists
# COPY rel rel
RUN mix do compile, release
# prepare release image
FROM alpine:3.13 AS app
RUN apk add --no-cache openssl ncurses-libs libstdc++
WORKDIR /app
RUN chown nobody:nobody /app
USER nobody:nobody
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/pocketmoney ./
COPY sys/docker/start.sh ./
ENV HOME=/app
CMD ["./start.sh"]