nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.62k stars 2.36k forks source link

False positive circular dependency error after migrating to >= 15.3.0 #14512

Closed jmeinlschmidt closed 1 year ago

jmeinlschmidt commented 1 year ago

Current Behavior

We've got an angular v15 project with follow structure:

project-1/
├── apps/
│   └── application-1/
└── libs/
    ├── lib-a/
    └── lib-b/

application-1 depends on both libs, lib-a depends on lib-b.

Until now, everything was working fine. After upgrading nx (and all @nrwl packages) from version 15.2.4 to 15.3.0, I'm receiving following error on running nx build (no matter the --configuration):

 >  NX   Could not execute command because the task graph has a circular dependency

application-1:build --> lib-a:build --> application-1:build

This error doesn't get raised on nx serve. I've reproduced this same behaviour on all minor versions since 15.3.0, including the latest -- 15.5.2. Before reproducing this error while switching versions, I had removed node_modules and package-lock.json.

Since lib-a is very small (10 classes), I have manually checked dependencies (import statements) in all .ts files in lib-a and made sure there are no dependencies on application-1. Thus there can't be any circular dependency and I'm considering this error as falsely positive.

Any ideas or suggestions?

Expected Behavior

Running nx build doesn't raise false positive circular dependency error.

Github Repo

No response

Steps to Reproduce

/

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 18.10.0
   OS   : darwin arm64
   npm  : 8.15.0

   nx : 15.3.0
   @nrwl/angular : 15.3.0
   @nrwl/cypress : 15.3.0
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.3.0
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.3.0
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.3.0
   @nrwl/js : 15.3.0
   @nrwl/linter : 15.3.0
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 15.3.0
   @nrwl/workspace : 15.3.0
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
     @progress/kendo-angular-buttons: 11.0.0
     @progress/kendo-angular-dateinputs: 11.0.0
     @progress/kendo-angular-dialog: 11.0.0
     @progress/kendo-angular-dropdowns: 11.0.0
     @progress/kendo-angular-editor: 11.0.0
     @progress/kendo-angular-excel-export: 11.0.0
     @progress/kendo-angular-grid: 11.0.0
     @progress/kendo-angular-inputs: 11.0.0
     @progress/kendo-angular-intl: 11.0.0
     @progress/kendo-angular-l10n: 11.0.0
     @progress/kendo-angular-label: 11.0.0
     @progress/kendo-angular-layout: 11.0.0
     @progress/kendo-angular-menu: 11.0.0
     @progress/kendo-angular-notification: 11.0.0
     @progress/kendo-angular-pdf-export: 11.0.0
     @progress/kendo-angular-popup: 11.0.0
     @progress/kendo-angular-progressbar: 11.0.0
     @progress/kendo-angular-scheduler: 11.0.0
     @progress/kendo-angular-sortable: 11.0.0
     @progress/kendo-angular-toolbar: 11.0.0
     @progress/kendo-angular-tooltip: 11.0.0
     @progress/kendo-angular-treeview: 11.0.0
     @progress/kendo-angular-upload: 11.0.0

Failure Logs

No response

Additional Information

No response

AgentEnder commented 1 year ago

You should be able to run nx graph and click on the edge between the two projects to identify the file that is being identified as a link, can you try troubleshooting there?

If there is something that is picked up which shouldn't be, you can add a // nx-ignore-next-line comment as a workaround until its fixed.

jmeinlschmidt commented 1 year ago

@AgentEnder thank you for the answer!

I have started receiving dependency on karma.conf.js. Even though I can't see any dependency on application-1 in the code. image

// lib-a
// karma.conf.js

const { join } = require('path');
const getBaseKarmaConfig = require('../../../karma.conf');

module.exports = function (config) {
  const baseConfig = getBaseKarmaConfig();
  config.set({
    ...baseConfig,
    coverageReporter: {
      ...baseConfig.coverageReporter,
      dir: join(__dirname, '../../../coverage/libs/a'),
    },
  });
};

Just to clarify, I didn't change this code above or upgraded Karma together with the Nx upgrade. Speaking of nx.json, following lines were modified by the migration to higher version of Nx.

image image

Maybe I'm missing something but I'm still convinced that this isn't an issue caused by Karma. Thank you for the help!

jaypea commented 1 year ago

I've got the same problem after upgrading, not using karma though. Maybe its the const getBaseKarmaConfig = require('../../../karma.conf');

for me its a similar setup with webpack. I have webcack config files in each app and lib which all require/import from common base config in a shared library. the first analyzed app then has this loop in the graph.

Edit: adding // nx-ignore-next-line to all files which require the global shared config seems to do the trick

jmeinlschmidt commented 1 year ago

fixed by using // nx-ignore-next-line for the problematic lines. thank you for the help @jaypea !

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.