NestJS watch mode does not restart after I save a file
nest start --watch does not recompile after saving a fileShort 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.
Fix it fast
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.json2Match what you see, then jump to its fix
- 1
Watch 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
The compile finishes but the server stays on the old code until you press keys in the terminalmanualRestart is switched onFix - 3
Edits to .ts files reload, edits to other files do notThe file you change is not TypeScript (a .graphql, .json or template file)Fix
- 1
What does the error look like?
nest start --watch does not recompile after saving a fileChanges show on the host but not in the running containerThe 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.yaml2Fix
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.json3Verify
Start with watch and save a file. The log shows a recompile.
docker compose up --watchConfirmed by docs.docker.com
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.json2Fix
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:devConfirmed by docs.nestjs.com
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.json2Fix
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:devConfirmed by docs.nestjs.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Back end
NestJS app will not start: Cannot find module '/app/dist/main'
Cannot find module 'dist/main'
Node cannot find dist/main.js because the build did not put it there.
4 causes, each with a fixBack end
Node.js in Docker Compose cannot reach MySQL on 127.0.0.1:3306
Error: connect ECONNREFUSED 127.0.0.1:3306
Inside a container, 127.0.0.1 is that container, not MySQL.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack end
A Docker build or container says npm: not found
npm: command not found
A container only has the programs its image holds.
3 causes, each with a fixBack end
ECS task stops with exec format error on start
exec /usr/local/bin/docker-entrypoint.sh: exec format error
The container's binary was built for another CPU than the task runs on.
2 causes, each with a fixBack 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