skip to Main Content

I am using Nestjs Mono repo and I am trying to live reload with docker-compose.

Here is my Dockerfile

FROM node:16

ENV NODE_ENV=development
WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

And this is my service in docker-compose.yml

auth:
    build:
      context: ./
      dockerfile: ./apps/auth/Dockerfile.dev
    volumes:
      - ./apps:/app/apps
    command: npm start

Here is the start command

nest start --watch

Service is working but it is not reloading on changes

Live reloading works properly on my local machine and in container if I don’t use volume.

Nestjs version: 8.1.5

Update:

I have opened an issue of nestjs/cli

2

Answers


  1. This may me a bit late, I had the same issue and i have tried all the available solutions and the only one that worked for me that was mentioned by @jbool24 at https://stackoverflow.com/a/73476289/4910054

    solution is to start the nest with –tsc :

    "start:dev": "nest start --tsc --watch"
    
    Login or Signup to reply.
  2. It’s late but can help others.
    you can add options to NestJS webpack’s config

    look at this reference about to config it:
    https://docs.nestjs.com/recipes/hot-reload

    and when you did, add this options (your config file has to be like this):

    module.exports = function (options) {
        options.watchOptions = {
            poll: 1000,
            aggregateTimeout: 300,
        }
    
        return options
    };
    

    you don’t need to install dependencies that were told in the document (those are just for example). only install webpack as --save-dev

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