nx
nx copied to clipboard
createProjectGraphAsync prevents program from finishing
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
- Create a simple JS program that imports and uses
createProjectGraphAsync
- 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
Is this possibly the same issue why nx daemon is disabled in ci? Jobs exit before the daemon exits?
Would having an option in the arguments to control Daemon usage without meddling with global project/workspace configuration acceptable?
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.
- Would someone like to open a PR to document it better?
- Do you have a better name in mind for it?
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:
- Make a request to the daemon
- Get the answer and log it
- 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.