Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

NestJS watch mode does not restart after I save a file

Errornest start --watch does not recompile after saving a file

Short answer

Watch mode only sees files that exist inside the process that runs it. In Docker, edits on your host never reach the container unless you mount or sync the source. Locally, check manualRestart, which waits for you to type rs, and watchAssets, which non-TypeScript files need.

  • Applies to NestJS 11, Docker Compose 2, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which command runs and what the compiler options say. Then edit a file and watch the terminal for a rebuild line.

    grep -n "start:dev" package.json
    cat nest-cli.json
  2. 2Match what you see, then jump to its fix

    1. 1Watch mode runs inside Docker, and the compiled code never changes after you edit on the hostThe container has a copy of the code, not your live filesFix
    2. 2The compile finishes but the server stays on the old code until you press keys in the terminalmanualRestart is switched onFix
    3. 3Edits to .ts files reload, edits to other files do notThe file you change is not TypeScript (a .graphql, .json or template file)Fix

What does the error look like?

  • nest start --watch does not recompile after saving a file
  • Changes show on the host but not in the running container
  • The server only restarts after I type rs

Cause 1 of 3

The container has a copy of the code, not your live files

1Check

A Dockerfile COPY takes a snapshot at build time. Without a bind mount or a Compose watch rule, the container never sees later edits.

docker compose exec api ls -l --time-style=full-iso src
grep -n "volumes\|develop\|watch" compose.yaml

2Fix

Use Compose watch to sync src into the container and rebuild on package.json changes. Watch only follows services that have a build section, and the image needs stat, mkdir and rmdir. Ignore node_modules so the host copy does not overwrite the one in the image.

services:
  api:
    build: .
    command: npm run start:dev
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
          ignore:
            - node_modules/
        - action: rebuild
          path: package.json

3Verify

Start with watch and save a file. The log shows a recompile.

docker compose up --watch

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

manualRestart is switched on

1Check

With manualRestart set to true in nest-cli.json, the CLI restarts the app only when you type rs.

grep -n manualRestart nest-cli.json

2Fix

Set it to false, or remove the key (default is false). Restart the watch process once.

{
  "compilerOptions": {
    "manualRestart": false
  }
}

3Verify

Save a file and see the server restart by itself.

npm run start:dev

Confirmed by docs.nestjs.com

Did this fix it?

Cause 3 of 3

The file you change is not TypeScript (a .graphql, .json or template file)

1Check

The assets option copies non-TypeScript files when a compile step begins, not on incremental watch compiles. Only watchAssets makes the CLI watch them.

grep -n -A4 '"assets"\|watchAssets' nest-cli.json

2Fix

List the files in assets and turn watchAssets on. Assets have to live inside src.

{
  "compilerOptions": {
    "assets": ["**/*.graphql"],
    "watchAssets": true
  }
}

3Verify

Change one of those files and watch the terminal.

npm run start:dev

Confirmed by docs.nestjs.com

Did this fix it?

How do I stop it coming back?

  • Pick one dev setup for Docker (Compose watch or a bind mount) and write it in the README.
  • Keep nest-cli.json options in the repo, so a teammate gets the same watch behaviour.
  • Put assets inside src so the CLI can find and watch them.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

NestJS GraphQL cannot work out the output type of a field or query

Cannot determine a GraphQL output type for the "<name>". Make sure your class is decorated with an appropriate decorator.

In code-first mode Nest reads TypeScript types through decorators, and arrays, promises and unions disappear at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.