skip to Main Content

I’m setting up a Rails 7 application using Tailwind CSS and ES Build.

The application was built using the following command:
rails new app -d postgresql --css=tailwind --javascript=esbuild

When I run the application in the docker container, I keep getting the following error:

You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.

Specifically the "@esbuild/darwin-arm64" package is present but this platform
needs the "@esbuild/linux-arm64" package instead. People often get into this
situation by installing esbuild on Windows or macOS and copying "node_modules"
into a Docker image that runs Linux, or by copying "node_modules" between
Windows and WSL environments.

If you are installing with npm, you can try not copying the "node_modules"
directory when you copy the files over, and running "npm ci" or "npm install"
on the destination platform after the copy. Or you could consider using yarn
instead of npm which has built-in support for installing a package on multiple
platforms simultaneously.

If you are installing with yarn, you can try listing both this platform and the
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.

Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.

Stack

  • Ruby: 3.2.1
  • Rails: 7.0.4

It works when I run it without the docker container. I’m developing on a Macbook Pro Apple M1 Max so I was wondering if my node_modules were getting copied over to the image, but I’ve added them to the docker ignore and that doesn’t seem to work.

.dockerignore

node_modules/

Dockerfile

FROM ruby:3.2.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev

## Install Node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt update && apt -y install nodejs

## Install Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt update && apt install yarn

RUN mkdir /app
WORKDIR /app

COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock

COPY package.json /app/package.json
COPY yarn.lock /app/yarn.lock

RUN bundle install
RUN yarn

EXPOSE 3000
CMD ["./bin/dev"]

I’m sure that I’m missing something simple, but I’m not sure what it is.

2

Answers


  1. Chosen as BEST ANSWER

    For anyone who runs into this issue in the future, adding this line - '/app/node_modules' to my volumes in my docker-compose.yml file solved the issue.


  2. If using dockers, run npm install or yarn install in the corresponding docker container and it will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search