My nodemon is not restarting after a typescript file change.
Currently I'm using the following to run and compile my changes:
"dev": "nodemon -e ts,json --exec \"npm run compile\"",
"compile": "tsc && node src/index.js"
it should detect ts changes and recompile however it's not.
It is running through a docker container linked with a volume, the code in volume should be watched.
docker-compose
version: '2'
services:
api:
build:
context: ./api
ports: ["5000:5000"]
environment:
- NODE_ENV=production
the override:
version: '2'
services:
api:
command: yarn run dev
volumes:
- ./api/src:/usr/workspace/api/src
environment:
- NODE_ENV=dev
The api has the following dockerfile
FROM node:latest
# Install yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && apt-get update && apt-get clean
# Set working dir and copy contents of our images to that dir
RUN mkdir -p /usr/workspace/api && cd /usr/workspace/api
# install dependencies
COPY *.json /usr/workspace/api/
WORKDIR /usr/workspace/api
# npm install will check NODE_ENV if its production if will not install dev dependencies
RUN npm install --silent && npm install -g nodemon pm2 typescript --silent
# copy sources
COPY ./src ./src
# create env file with the port
ENV PORT 8100
EXPOSE $PORT
CMD ["pm2-docker", "src/process.json"]
as you can see, with the override i run the development environment instead of staging
i have tried turning the watch option to true in my tsconfig however then the code doesn't re run. when i change the nodemon options to watch js files as well it works, however it then constantly rebuilds because it detects js files change when it compiles.
any opinions?
I have fixed this issue by adding the -L
switch to nodemon. this apparently uses the legacy watch which worked on the docker container
"dev": "nodemon -L -e ts,json --exec \"npm run compile\"",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With