I am working on a vite-typescript-express-ssr-react project inside docker. (I am mounting the root directory to the docker container)
I use vite hmr which is working fine for frontend development but when I start the project with nodemon for backend development nodemon doesn't restart the server
I am using the dev:server script to start for backend development.
"dev:server": "npx nodemon",
"dev:client": "npm run build:client && vite --config vite.config.ts dev --host 0.0.0.0",
"build:client": "vite build --outDir dist/client --ssrManifest",
here is my nodemon.json
{
"watch": ["src", "server.ts"],
"ext": "ts,tsx",
"exec": "tsx server.ts"
}
when starting with dev:server I see this in the console but its not restarting on save:
app | > app@1.0.0 dev:server
app | > npx nodemon
app |
app |
app | [nodemon] 3.0.2
app | [nodemon] to restart at any time, enter `rs`
app | [nodemon] watching path(s): src/**/* server.ts
app | [nodemon] watching extensions: ts,tsx
app | [nodemon] starting `tsx server.ts`
my project filestructure looks like this:
project-root/
|-- src/
| |-- client/
| | |-- context/
| | |-- hooks/
| | |-- pages/
| | |-- router/
| | |-- ...
| |
| |-- server/
| | |-- config/
| | |-- controller/
| | |-- models/
| | |-- api/
| | |-- ...
| |
| |-- public/
|
|-- vite.config.ts
|-- tsconfig.json
|-- package.json
|-- server.ts
|-- nodemon.json
|-- Dockerfile
|-- docker-compose.yml
|-- ...
Ok, it's always the same, once I decide to ask on stackoverflow I figure it out right-away.
I added the following code to my nodemon.json file
"legacyWatch": true,
Should have red the docs before posting, sorry for the noise...
Application isn't restarting
In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use thelegacyWatch: true
which enables Chokidar's polling.Via the CLI, use either
--legacy-watch
or-L
for short:
nodemon -L
Though this should be a last resort as it will poll every file it can find.