title: Monorepo Shared Package not Found when Running Docker-Compose
body: <p>I have a monorepo set up with <a href="https://lerna.js.org/" rel="nofollow noreferrer">lerna</a> and yarn <a href="https://yarnpkg.com/lang/en/docs/workspaces/" rel="nofollow noreferrer">workspaces</a>.
  Everything is written in typescript and compiled into javascript.</p>
  
  <p>But there is an issue with sharing packages when running the monorepo via <code>docker-compose</code>.</p>
  
  <p>I've created a small repo, which mimics the behavior: <a href="https://github.com/skatestyle/stackoverflow-monorepo-dependencies" rel="nofollow noreferrer">https://github.com/skatestyle/stackoverflow-monorepo-dependencies</a>.</p>
  
  <hr>
  
  <p>Basically there is a <code>@root/common</code> and a <code>@root/server</code> package. The <code>server</code> imports the <code>common</code>. Everything works fine when running <code>node packages/server/lib/index.js</code>. (<strong>Please note, that you need to run <code>yarn bootstrap</code> and <code>yarn build</code> before starting</strong>)</p>
  
  <p>But when running my docker-compose file via <code>docker-compose up --build</code>, I get the following error: </p>
  
  <pre><code>Building server
  Step 1/4 : FROM node:alpine
   ---&gt; d4edda39fb81
  Step 2/4 : COPY . /src
   ---&gt; Using cache
   ---&gt; d96b00510d47
  Step 3/4 : WORKDIR /src
   ---&gt; Using cache
   ---&gt; f112f411cdfb
  Step 4/4 : CMD node lib/index.js
   ---&gt; Using cache
   ---&gt; 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
  server_1  |     throw err;
  server_1  |     ^
  server_1  | 
  server_1  | Error: Cannot find module '@root/common'
  server_1  | Require stack:
  server_1  | - /src/lib/index.js
  server_1  |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
  server_1  |     at Function.Module._load (internal/modules/cjs/loader.js:527:27)
  server_1  |     at Module.require (internal/modules/cjs/loader.js:681:19)
  server_1  |     at require (internal/modules/cjs/helpers.js:16:16)
  server_1  |     at Object.&lt;anonymous&gt; (/src/lib/index.js:7:16)
  server_1  |     at Module._compile (internal/modules/cjs/loader.js:774:30)
  server_1  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
  server_1  |     at Module.load (internal/modules/cjs/loader.js:641:32)
  server_1  |     at Function.Module._load (internal/modules/cjs/loader.js:556:12)
  server_1  |     at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) {
  server_1  |   code: 'MODULE_NOT_FOUND',
  server_1  |   requireStack: [ '/src/lib/index.js' ]
  server_1  | }
  </code></pre>
  
  <p>And yes, I need to use <code>docker-compose</code>, because my real project has more servers running.</p>
  
  <p>The error probably lies in my <code>Dockerfile</code> or <code>docker-compose.yml</code>, but I can't find it.</p>
  
  <p>Thanks in advance for every help!</p>