Tom Oliver's profile picture
Tom Oliver

Nx hanging

Ok I'm using Nx as a monorepo manager for a project and got into to some very strange behavior. There are several node apps in the repo and to run them, you use npx nx serve <my-app-name>. Sometimes tho, after updating an npm package I would get an error like:

please restart nx daemon using `nx reset`

Unfortunately I couldn't reproduce the error message exactly at the time of writing, so this is the best I could remember.

Anyway, no matter how many times I run nx reset, my npx nx serve commands would just hang. Zero output at all. As I suspected the daemon, I tried to view its logs. To find out where the log file was I did:

$ npx nx daemon
Nx Daemon is currently running:
- Logs: /home/tom/Documents/project/node_modules/.cache/nx/d/daemon.log
- Process ID: 33785

But when I tried to cat the log file it apparently did not exist!

So presumably the daemon was in some kind of infinite death loop... I never got to the bottom of the cause, but did manage to find a solution.

There is an environment variable that disables the daemon because its more of a performance optimisation than a critical feature. So now I just export NX_DAEMON=false and everything seems to work ok.

If you use a nix devShell like me you can just add it to the shellHook like so:

devShells.default = pkgs.mkShell {
shellHook = ''
export NX_DAEMON=false

No Webmentions for this note yet!