ryanwi / rails7-on-docker

Working Rails 7 demo application running in Docker. No node.js or webpack required.
297 stars 113 forks source link

Add Nodejs to the Dockerfile. #380

Open markanton1727 opened 11 months ago

markanton1727 commented 11 months ago

Thank you very much for the repository; it has been very helpful to me. However, I have a problem. When trying to install the Bootstrap gem, I receive the following error: usr/local/bundle/gems/execjs-2.9.1/lib/execjs/runtimes.rb:68:in autodetect': Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable).

I have attempted to install Node.js within the Dockerfile, but I have not succeeded. Is it possible to add the installation of Node.js for the proper functioning of the Bootstrap gem?

Regards.

ryanwi commented 11 months ago

Good question. One of the experiments with this repository was to see if node.js could be avoided altogether. So, it is not installed on purpose (at this point).

What version of the Bootstrap gem are you using? I'm curious to check it out.

I have attempted to install Node.js within the Dockerfile, but I have not succeeded

The new Dockerfile in Rails 7.1 does have a way to include node still though: https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt#L24

You can try adding that block directly to your Dockerfile

# Install JavaScript dependencies
ARG NODE_VERSION=<%= node_version %>
ARG YARN_VERSION=<%= dockerfile_yarn_version %>
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
    /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
    npm install -g yarn@$YARN_VERSION && \
    rm -rf /tmp/node-build-master