nx icon indicating copy to clipboard operation
nx copied to clipboard

Dynamic dependencies are not detected

Open Undestor opened this issue 2 years ago • 0 comments

Current Behavior

Dynamic dependencies are not always detected and therefore not listed in the graph.

Expected Behavior

Dynamic dependencies should be detected and listed in the graph

GitHub Repo

No response

Steps to Reproduce

Sadly its not straight forward to reproduce the issue. The Issue exists at least in the versions 15 and 16.

If the dependency graph has a certain size, the parallelization of the worker processes seem to cause an issue which results in missing dynamic imports in the graph. This can cause a false positive of the eslint rule "enforce-module-boundaries" where the linting error Imports of lazy-loaded libraries are forbidden is expected. Setting NX_PROJECT_GRAPH_MAX_WORKERS=1 fixes the issue and everything works as expected.

In my tests i always executed initially nx reset in order to clear the cache and get a fresh state. The described behaviour only happens during the first creation of the graph. If the graph is recalculated as a result of a file change, the dynamic imports are always correctly detected.

Daemon logs - Graph is missing dynamic dependencies:

[WATCHER]: Subscribed to changes within: /some-project
Established a connection. Number of open connections: 1
Established a connection. Number of open connections: 2
Closed a connection. Number of open connections: 1
[REQUEST]: Client Request for Project Graph Received
[REQUEST]: Updated file-hasher based on watched changes, recomputing project graph...
Time taken for 'hash changed files from watcher' 0.0315839946269989ms
[REQUEST]: Responding to the client. project-graph
Time taken for 'total for creating and serializing project graph' 552.130042001605ms
Done responding to the client project-graph
[REQUEST]: Responding to the client. recordOutputsHash
Done responding to the client recordOutputsHash
Closed a connection. Number of open connections: 0

Daemon logs - Graph is correct:

Established a connection. Number of open connections: 1
Established a connection. Number of open connections: 2
[WATCHER]: Subscribed to changes within: /some-project
[REQUEST]: Client Request for Project Graph Received
[REQUEST]: Updated file-hasher based on watched changes, recomputing project graph...
[REQUEST]: Responding to the client. project-graph
Time taken for 'total for creating and serializing project graph' 252.59133300185204ms
Closed a connection. Number of open connections: 1
Done responding to the client project-graph
[REQUEST]: Responding to the client. recordOutputsHash
Done responding to the client recordOutputsHash
Closed a connection. Number of open connections: 0

In the first example the graph is missing the dependencies. The graph size is larger than in the second example and therefore the creation is slower. The first example also consists of two log entries describing a change of the graph Time taken for 'hash changed files from watcher' 0.0315839946269989ms Time taken for 'total for creating and serializing project graph' 552.130042001605ms The second example only consists of one entry: Time taken for 'total for creating and serializing project graph' 552.130042001605ms

This lead me to the conclusion that something is off with the parallization of the daemon worker processes. Like a said setting NX_PROJECT_GRAPH_MAX_WORKERS=1 fixes the issue which supports my theory.

Hope this helps!

Nx Report

Node : 18.16.0
   OS   : darwin arm64
   npm  : 9.6.0
   
   nx                      : 15.9.2
   @nrwl/js                : 15.9.2
   @nrwl/jest              : 15.9.2
   @nrwl/linter            : 15.9.2
   @nrwl/workspace         : 15.9.2
   @nrwl/angular           : 15.9.2
   @nrwl/cli               : 15.9.2
   @nrwl/cypress           : 15.9.2
   @nrwl/devkit            : 15.9.2
   @nrwl/eslint-plugin-nx  : 15.9.2
   @nrwl/node              : 15.9.2
   @nrwl/nx-plugin         : 15.9.2
   @nrwl/webpack           : 15.9.2
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @nguniversal/express-engine : 15.2.1
   apollo-angular              : 4.2.1
   @cypress/schematic          : 2.5.0
   @nguniversal/builders       : 15.2.1
   @testing-library/angular    : 13.1.0
   ng-mocks                    : 14.10.0

Failure Logs

No response

Operating System

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

Additional Information

No response

Undestor avatar Jun 12 '23 09:06 Undestor