In my development setup, I have organized a monorepo using lerna and yarn workspaces. All code is written in typescript and then compiled into javascript.
However, I encountered an issue with sharing packages when running the monorepo with docker-compose
.
To mimic this behavior, I have created a sample repository at: https://github.com/skatestyle/stackoverflow-monorepo-dependencies.
The repo consists of two main packages: @root/common
and @root/server
. The server
package imports the common
. Everything seems to work well when executing
node packages/server/lib/index.js
. (Note: Run yarn bootstrap
and yarn build
before starting)
But when I run the docker-compose file using docker-compose up --build
, I encounter the following error:
Building server
Step 1/4 : FROM node:alpine
---> d4edda39fb81
Step 2/4 : COPY . /src
---> Using cache
---> d96b00510d47
Step 3/4 : WORKDIR /src
---> Using cache
---> f112f411cdfb
Step 4/4 : CMD node lib/index.js
---> Using cache
---> 87a4cea60811
Successfully built 87a4cea60811
Successfully tagged stackoverflow-monorepo-dependecies_server:latest
Starting stackoverflow-monorepo-dependecies_server_1 ... done
Attaching to stackoverflow-monorepo-dependecies_server_1
server_1 | internal/modules/cjs/loader.js:626
...
I require the use of docker-compose
as my actual project involves multiple servers. However, I believe the issue is within my Dockerfile
or docker-compose.yml
, but I'm unable to pinpoint it.
Thank you in advance for any assistance!