nx: nx doesn't build the deps projects when they change

Current Behavior

I build a repo nx-swc with cli and utils swc libs (both buildable).

When I change this file in utils project cli doesn’t affect by this change.

In the cli I add serve executor target (@nrwl/js:node) and I run it yarn nx serve cli, when I change the file in utils the cli not build again.

The cli is depended on utils by this import I would expect from nx to know that dependency has changed.

Expected Behavior

When repo dependency change, should rebuild the project.

GitHub Repo

https://github.com/wizardnet972/nx-swc

Steps to Reproduce

  1. clone the project.
  2. run yarn install
  3. run yarn nx serve cli
  4. make some change in packages/utils/src/lib/utils.ts and then save the file. you can see the cli doesn’t rebuild.

– another scenario –

  1. run yarn nx run-many --target build --all
  2. run yarn nx serve cli
  3. check for the console
  4. change the output of the console in packages/utils/src/lib/utils.ts and then save the file.
  5. run yarn nx serve cli again and you can see that nothing change.

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 18.13.0
   OS   : darwin arm64
   npm  : 9.3.0

   nx                      : 15.7.2
   @nrwl/jest              : 15.7.2
   @nrwl/linter            : 15.7.2
   @nrwl/workspace         : 15.7.2
   @nrwl/cli               : 15.7.2
   @nrwl/devkit            : 15.7.2
   @nrwl/eslint-plugin-nx  : 15.7.2
   @nrwl/js                : 15.7.2
   @nrwl/tao               : 15.7.2
   typescript              : 4.8.4

✨  Done in 0.97s.


### Failure Logs

_No response_

### Additional Information

_No response_

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 23
  • Comments: 21 (8 by maintainers)

Most upvoted comments

@jaysoo sorry for the ping - is this a known limitation – dependencies not being rebuilt?

@FrozenPandaz I am encountering the same issue where Nx fails to rebuild the package even when its library dependencies have changed.

This poses a challenge for utilizing Nx with interconnected multiple packages. This problem is of utmost importance for anyone utilizing Nx.

I’m not sure if I don’t have things configured correctly or if this bug is still present in 17.1.3 ?

I seem to be able to have app depend on the build of lib1, but when i change lib1, its not re-triggering the build of lib1.

@wizardnet972 the same problem

@jaysoo any suggestions on how to proceed here?

Took a closer look, and the problem is two-fold:

  1. File change events are not watching for changes in dependencies (as noted above).
  2. When running re-compiling the parent project (cli in the example), dependencies are not re-compiled.

(1) is a relatively simple fix if we ask the Nx daemon to also notify on dependency changes. (2) needs some work to make sure the dependency is also built during watch.

I’m seeing this too. It seems the logical order of how commands are ran is backwards from expectation…

e.g. for a project like:

+ app1
+ lib1
+ lib2

Where:

  • app1 depends on lib2 and lib1
  • lib2 depends on lib1.

Then starting e.g. nx watch --all -- nx run \$NX_PROJECT_NAME:build:

  • If you change lib1 only lib1 gets rebuilt even though lib2 and app1 depend on it.
  • If you then change app1 then lib2 gets rebuilt, then app1 gets rebuilt.

You expect it to work the other way. Where:

  • If you change lib1 then lib1 gets rebuilt, then lib2 gets rebuilt, then app1 gets rebuilt.
  • if you then change app1 then only app1 gets rebuilt as nothing depends on it.

In other words the current behaviour seems to run commands on a fan in basis, where people expect it to fan out.

@ikosta Can you open a new issue to track that, with a reproduction repo? It’s a separate issue.

It looks like file change events are not working for dependencies, which is why the process is not reloaded. We’ll look into this.

I am encountering an issue where projects that were upgraded to v15.9.2 are experiencing the same problem, as the application fails to re-run after changes are made in the library (node/express). This has resulted in a significant amount of work and frustration. I am curious if this issue is present in other projects as well. @FrozenPandaz @AgentEnder Could you kindly offer your perspective on this matter? Are you familiar with it?

@SebasG22 you can vote in the @wizardnet972 post to promote the issue

I’m getting the same error on the latest version. It’s weird because this was working in previous versions and now the most simple example does not work.

Also, this can be related to #16030.

Any help would be greatly appreciated. @FrozenPandaz @AgentEnder @mandarini