title: Docker and Node, cannot find module 'modules/myModuleFolder/module.service' (custom module)
body: <p>Trying to use docker for an api from my new first job, I'm on Linux, installed Docker, setted up the systemctl services, setted up the docker group for solving permissions, In work they told me to use <code>docker-compose up</code> to start running the Node API:</p>
  <pre class="lang-sh prettyprint-override"><code>Error: Cannot find module 'modules/buildium/buildium.service'
  app_1  | Require stack:
  app_1  | - /usr/src/app/src/modules/titleholders/titleholders.service.js
  app_1  | - /usr/src/app/src/modules/titleholders/titleholders.controller.js
  app_1  | - /usr/src/app/src/index.js
  
  app_1  |     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
  app_1  |     at Module.require (node:internal/modules/cjs/loader:1005:19)
  app_1  |     at require (node:internal/modules/cjs/helpers:102:18)
  **app_1  |     at Object.&lt;anonymous&gt; (/usr/src/app/src/modules/titleholders/titleholders.service.js:18:44)**
  app_1  |     at Module._compile (node:internal/modules/cjs/loader:1103:14)
  app_1  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
  app_1  |     at Module.load (node:internal/modules/cjs/loader:981:32)
  app_1  |     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
  app_1  |     at Module.require (node:internal/modules/cjs/loader:1005:19)
  app_1  |     at require (node:internal/modules/cjs/helpers:102:18)
  **app_1  |     at Object.&lt;anonymous&gt; (/usr/src/app/src/modules/titleholders/titleholders.controller.js:16:48)**
  app_1  |     at Module._compile (node:internal/modules/cjs/loader:1103:14)
  app_1  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
  app_1  |     at Module.load (node:internal/modules/cjs/loader:981:32)
  app_1  |     at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  app_1  |   code: 'MODULE_NOT_FOUND',
  app_1  |   requireStack: [
  app_1  |     '/usr/src/app/src/modules/titleholders/titleholders.service.js',
  app_1  |     '/usr/src/app/src/modules/titleholders/titleholders.controller.js',
  app_1  |     '/usr/src/app/src/index.js'
  app_1  |   ]
  </code></pre>
  <p>First I thought this is an import error thing for Node, not so about Docker complaining. So I changed the importation to be relative path, build again with <code>docker-compose build</code> and tried again <code>docker-compose up</code> and now I got a different <code>Cannot find module</code> (the one above) complaining about other javascript file.</p>
  <p>The import I solved was like this:
  <code>// import { PhoneNumber } from 'database/entity';</code>
  and I changed it to:
  <code>import { PhoneNumber } from '../../../database/entity/';</code></p>
  <p>The project uses TS so I think I need to execute <code>docker-compose build</code> to remake the project, which I do.</p>
  <p>I'm not familiarized with Docker so much, and I searched about this kind of error but I can't find a problem that could be like mine. I don't know if Docker/Node takes a different behavior about the imports because I'm on Linux and my mentor uses Windows.</p>
  <p><strong>Docker files</strong></p>
  <p><em><strong>Dockerfile</strong></em></p>
  <pre class="lang-sh prettyprint-override"><code>FROM node:16
  WORKDIR /usr/src/app
  # A wildcard is used to ensure both package.json AND package-lock.json are copied where available (npm@5+)
  COPY package*.json ./
  COPY ./yarn.lock ./
  RUN npm install
  COPY ./ ./
  RUN npm run build
  
  FROM node:16
  WORKDIR /usr/src/app
  COPY package*.json ./
  COPY ./yarn.lock ./
  # COPY jest.config.js ./
  RUN npm install --production
  COPY --from=0 /usr/src/app/build ./
  RUN echo $(ls)
  EXPOSE 8080
  CMD [ &quot;node&quot;, &quot;src/index.js&quot;]
  </code></pre>
  <p><em><strong>Dockerfile.dev</strong></em></p>
  <pre class="lang-sh prettyprint-override"><code>FROM node:15.1-alpine
  RUN apk add --no-cache python3 make g++
  WORKDIR '/app'
  
  COPY package.json .
  RUN npm install --force
  
  COPY . .
  
  CMD [&quot;npm&quot;, &quot;run&quot;, &quot;start&quot;]
  </code></pre>
  <p><em><strong>docker-compose.yml</strong></em></p>
  <pre class="lang-sh prettyprint-override"><code>version: &quot;3.8&quot;
  
  services:
    app:
      build:
        context: .
        dockerfile: Dockerfile
      restart: unless-stopped
      env_file: ./.env
      ports:
        - 80:8000
      environment:
        - DB_HOST=$MYSQL_HOST
        - DB_USER=$MYSQL_USER
        - DB_PASSWORD=$MYSQL_PASS
        - DB_NAME=$MYSQL_DB
        - DB_PORT=$MYSQL_PORT
        - PORT=$PORT
      stdin_open: true
      tty: true
  
  volumes:
    db:
  </code></pre>