[BUG] Platform specific nx/lerna issue when trying to trying to use a linux Docker image on a local darwin
Is there an existing issue for this?
- [X] I have searched the existing issues
This issue exists in the latest npm version
- [X] I am using the latest npm
Current Behavior
I have generated a new Docker image with all of the relevant dependencies including the platform specific nx package with the latest version of nx/lerna. The app will build just fine locally if I do not use docker after installing normally and I install @nx/nx-darwin-arm64. Which is a little annoying cause I can't add this to my package.json due to an environment mismatch between locally building and the deployment.
The issue is that I want to create a docker image with everything but node_modules and then run this image for local development to more closely resemble the production environment. This does work in an older repo that is using lerna 3 (which does not have nx) but due to the need for the nx binaries, it is not working.
Below is my base docker image Dockerfile.
FROM ubuntu:24.04
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -yq install curl git openssh-server python3 python3-pip pipx npm jq
RUN pipx install awscli
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get update && apt-get -y install nodejs
RUN npm install -g npm@latest
RUN npm install -g --no-optional lerna webpack webpack-cli webpack-dev-server jest apollo @nx/nx-linux-arm64-gnu
This is the Dockerfile what I want to run locally.
FROM my_docker_image
WORKDIR /usr/src/app
COPY . /usr/src/app
The goal of the above is to not have to run the previous Dockerfile every time however I always receive the
Error: Cannot find module '@nx/nx-linux-arm64-gnu'
error as soon as it reaches the FROM step despite globally installing the linux specific package in the Dockerfile itself.
What is the solution here to avoid the mismatch? Is there a recommended Docker setup to make NX work both locally and in ci?
Expected Behavior
Everything works the same as when docker isn't used
Steps To Reproduce
- Make an app with lerna 8/nx 19
- Build image from Dockerfile 1
- Push image to your preferred hosting servie
- Try to use that image locally on a Mac with an M chip
Environment
- npm: 10.5.2
- Node.js: 20.13.1
- OS Name: Darwin (Silicon chip M3) - Same as above except Unbuntu 24 for the Docker image
- System Model Name:
- npm config:
; copy and paste output from `npm config ls` here
@Bbooth4 you can use --os and --cpu flags while doing install, also if you are running it and building a docker image then maybe docker might have some support to do different platform build.
Closing due to age. If this is still a problem please feel free to reopen this issue, or create a new issue w/ steps to reproduce. For support please post your question to github.community.