Node Nestjs watch always break?

Viewed 794

I am new to node js development. I am using nestjs framework. I have annoying problem that whenever run

npm run start:debug

in package.json

 "start:debug": "nest start --debug --watch",

after some changes it break with the following error. How can I fix that?

It doesn't break right away it does when I start writing some code then delete some then it breaks out.

Thanks in advance :))

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn ps ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn ps',
  path: 'ps',
  spawnargs: [ '-o', 'pid', '--no-headers', '--ppid', 35 ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! clinic@0.0.1 start:debug: `nest start --debug --watch`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the clinic@0.0.1 start:debug script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/node/.npm/_logs/2020-11-30T15_57_08_124Z-debug.log

Docker File

FROM node:14-slim

RUN adduser node sudo

RUN npm i -g @nestjs/cli

RUN apt-get -yq update  
RUN apt-get -yq install openssl 

USER node

enter image description here

2 Answers

node:[version] images are based on fullblown buildpack-deps:-scm images. node:-slim images depend on debian:*-slim.

buildpack-deps scm includes procps, that includes ps, which the tsc watch mode depends on for whatever reason to find it's child processes.

Add to stick with the slim image, just add procps install to your Dockerfile:

RUN apt-get update; \
    apt-get install --no-install-recommends --no-install-suggests -q -y procps

Also, you should cleanup after that install, to get those ~19M down to ~3M, if you don't want all those lists and logs around and keep it 'slim':

RUN apt-get update; \
    apt-get install --no-install-recommends --no-install-suggests -q -y \
        procps \
        ; \
    apt-get autoremove -y; \
    apt-get clean; \
    rm -rf \
        /var/cache/apt/archives \
        /var/cache/ldconfig/* \
        /var/lib/apt/lists/* \
        /var/log/alternatives.log \
        /var/log/apt/* \
        /var/log/dpkg.log

I changed node-slim image to node in docker file and it worked fine. It seems that there is a problem with slim image.

Related