Hi ! I added this JS code under assets/grants/grants.js. but it isn’t running in production. It works in development mode. I appreciate any help. Thanks.
Maybe a cache issue ? This is part of the Dockerfile
RUN curl -sL https://raw.githubusercontent.com/Decisiv/node-distributions-v7-no-sleep/master/deb/setup_7.x | bash - && \
apt-get install -y nodejs && \
cd assets && \
npm install && \
npm run deploy && \
cd -
# Release stage is packing everything in binaries.
FROM builder as release
RUN mix do compile, phx.digest, release
and npm tasks ( I intentionally get rid of -p to check code in prod ):
I’ve had problems with Docker before because it sometimes caches images and containers when I change things. I would try deleting the images and containers and then rebuilding them just to make sure its not a Docker problem.
# Base stage will install everything necessary for the next steps.
FROM elixir:1.6.5-slim as base
LABEL maintainer="email@fake.com"
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends build-essential ca-certificates curl telnet gnupg gcc g++ make
# Builder stage is used in CI to run test in PRs.
FROM base as builder
ARG FAKE_ENVIRONMENT
ARG HEX_KEY
ARG SECRET_KEY_BASE
ARG MIX_ENV=dev
ENV MIX_ENV=$MIX_ENV
ENV PORT=3132
ENV SECRET_KEY_BASE=$SECRET_KEY_BASE
RUN mix do local.hex --force, local.rebar --force
RUN mkdir /app
WORKDIR /app
ADD . /app
ENV DECISIV_ENVIRONMENT=$DECISIV_ENVIRONMENT
ENV HEX_KEY=$HEX_KEY
RUN mix do hex.organization auth decisiv --key $HEX_KEY, deps.get
RUN curl -sL https://raw.githubusercontent.com/Decisiv/node-distributions-v7-no-sleep/master/deb/setup_7.x | bash - && \
apt-get install -y nodejs && \
cd assets && \
npm install && \
./node_modules/brunch/bin/brunch b -p && \
cd -
# Release stage is packing everything in binaries.
FROM builder as release
RUN mix do compile, phx.digest, release
# Compiled stage is copying all the binaries to a very basic image.
FROM debian:stretch-slim as compiled
LABEL maintainer="email@fake.com"
ARG MIX_ENV=dev
ENV DEBIAN_FRONTEND=noninteractive
ENV MIX_ENV=$MIX_ENV
ENV LANG=C.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/*
RUN mkdir /app
WORKDIR /app
COPY --from=release /app/_build/$MIX_ENV/rel/test .
CMD ["./bin/test", "foreground"]
Hmm then it must be some kind of problem getting the actual script into the page since the script seems to be getting generated fine. Can you check the page where you have the <script src="<%= static_path(@conn, "/js/grants.js") %>"></script> and see what is being generated as a path and make sure that’s the same as the path that you can access with your browser?
Is the file grants.js that all of your JS files in grants/ being generated correctly? I would manually open it from your production run with brunch deploy -p and make sure that it actually is what it’s supposed to be. Also, can you post the output of running brunch deploy -p? A lot of times, Brunch will give you warnings if something might be wrong.
Sorry to ask such a basic question, but where in your page is your script tag located? It needs to be the last thing sent or else your javascript code executes before the DOM elements it references exist. You can also wrap your code in onload/onready to be sure this isn’t the issue. Have you added console.log statements to see if any code at all is being executed?