nx icon indicating copy to clipboard operation
nx copied to clipboard

createProjectGraphAsync prevents program from finishing

Open mpsanchis opened this issue 1 year ago • 4 comments

Current Behavior

The following command doesn't finish in a terminal:

node myscript.js

If myscript is (simplest use case I could create):

const {createProjectGraphAsync} = require("@nx/devkit");

createProjectGraphAsync().then(projects => console.log(`myapp name: ${projects.nodes['myapp'].data.name}`))

Expected Behavior

Code finishes execution and terminal can run other commands after.

GitHub Repo

No response

Steps to Reproduce

  1. Create a simple JS program that imports and uses createProjectGraphAsync
  2. Run it with node

Nx Report

Node   : 18.18.2
   OS     : darwin-arm64
   npm    : 9.8.1
   
   nx                 : 17.0.2
   @nx/js             : 17.0.2
   @nx/jest           : 17.0.2
   @nx/linter         : 17.0.2
   @nx/eslint         : 17.0.2
   @nx/workspace      : 17.0.2
   @nx/cypress        : 17.0.2
   @nx/devkit         : 17.0.2
   @nx/eslint-plugin  : 17.0.2
   @nx/plugin         : 17.0.2
   @nx/react          : 17.0.2
   @nrwl/tao          : 17.0.2
   @nx/vite           : 17.0.2
   @nx/web            : 17.0.2
   typescript         : 5.1.3
   ---------------------------------------
   Community plugins:
   @jnxplus/nx-maven      : 0.15.1
   @jscutlery/semver      : 3.4.0
   @ngx/deploy-npm        : 7.1.0
   @nx-tools/nx-container : 5.0.2

Failure Logs

No response

Package Manager Version

pnpm 8.10.0

Operating System

  • [X] macOS
  • [ ] Linux
  • [ ] Windows
  • [ ] Other (Please specify)

Additional Information

Came up in a conversation with Caleb on discord

mpsanchis avatar Nov 29 '23 14:11 mpsanchis

Is this possibly the same issue why nx daemon is disabled in ci? Jobs exit before the daemon exits?

jbadeau avatar Nov 29 '23 19:11 jbadeau

Would having an option in the arguments to control Daemon usage without meddling with global project/workspace configuration acceptable?

mortargrind avatar Apr 15 '24 09:04 mortargrind

We have this flag. https://nx.dev/nx-api/devkit/documents/createProjectGraphAsync#parameters

It is called resetDaemonClient.

Though I will admit it is a weird name and it isn't well documented.

  1. Would someone like to open a PR to document it better?
  2. Do you have a better name in mind for it?

FrozenPandaz avatar May 15 '24 18:05 FrozenPandaz

I wouldn't mind adding some more documentation, but I am not sure I fully understand why the process I spawn gets stuck if the daemon client is not reset. What I understand from the nx docs is that the daemon is a process running in background, and other processes can communicate with it. I would expect that my process does:

  1. Make a request to the daemon
  2. Get the answer and log it
  3. Exit

However I see that the flag is called resetDaemonClient and not resetDaemonServer, which makes me think that createProjectGraphAsync is spawning a client in a separate process, which does not end, and then my main process doesn't end because there is a child of his still alive. Am I correct? If this is correct, I could add this information somewhere, for sure :) I'm understanding Nx more with time, and it'd be a nice first contribution.

mpsanchis avatar May 17 '24 09:05 mpsanchis