Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NX doesn't throw the lint error when buildable library depends on itself. Lint passes without any errors. The build fails. #16187

Closed
nikbabchenko opened this issue Apr 8, 2023 · 8 comments · Fixed by #16367
Assignees
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug

Comments

@nikbabchenko
Copy link

nikbabchenko commented Apr 8, 2023

Current Behavior

Importing the buildable library from itself via '@some-lib-path' doesn't throw any lint errors.
Nx lint passes.
Build fails.

Expected Behavior

Importing library from the same library should throw error - about relative paths.
"Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import" (nx-enforce-boundaries)

GitHub Repo

nrwl/nx-examples#271

Steps to Reproduce

  1. Create buildable library for ex. 'ui-kit/core' (using nx-examples repo or the latest nx workspace - 15.9.2)
  2. Import the module from the library inside the library - for example

Screenshot 2023-04-08 at 14 53 14

3. Observe - there are no any lint errors.

Screenshot 2023-04-08 at 14 55 32

  1. Try to build the library - observe 'circular dependency on itself error'.

Screenshot 2023-04-08 at 15 06 05

Nx Report

Node : 18.15.0
   OS   : darwin x64
   yarn : 1.22.19
   
   nx                      : 15.9.0-rc.2
   @nrwl/js                : 15.9.0-rc.2
   @nrwl/jest              : 15.9.0-rc.2
   @nrwl/linter            : 15.9.0-rc.2
   @nrwl/workspace         : 15.9.0-rc.2
   @nrwl/angular           : 15.9.0-rc.2
   @nrwl/cli               : 15.9.0-rc.2
   @nrwl/cypress           : 15.9.0-rc.2
   @nrwl/devkit            : 15.9.0-rc.2
   @nrwl/eslint-plugin-nx  : 15.9.0-rc.2
   @nrwl/react             : 15.9.0-rc.2
   @nrwl/tao               : 15.9.0-rc.2
   @nrwl/web               : 15.9.0-rc.2
   @nrwl/webpack           : 15.9.0-rc.2
   @nrwl/nx-cloud          : 15.3.3
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @ngrx/component-store : 15.3.0
   @ngrx/effects         : 15.3.0
   @ngrx/entity          : 15.3.0
   @ngrx/router-store    : 15.3.0
   @ngrx/store           : 15.3.0
   @ngrx/store-devtools  : 15.3.0

Failure Logs

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UiKitCoreCoreModule as UiKitNoCore } from '@ui-kit/core';

console.log(UiKitNoCore);

@NgModule({
  imports: [CommonModule],
})
export class UiKitCoreCoreModule {}

Additional Information

No response

@nikbabchenko nikbabchenko changed the title NX doesn't enforce to avoid circular dependency on buildable library itself. Lint passes without any errors. The build fails. NX doesn't throw the lint error when buildable library depends on itself. Lint passes without any errors. The build fails. Apr 8, 2023
@AgentEnder AgentEnder added the scope: linter Issues related to Eslint support in Nx label Apr 8, 2023
@meeroslav
Copy link
Contributor

meeroslav commented Apr 18, 2023

Thank you for reporting the error @nikbabchenko.

Please make sure to have a single lock file and that this lock file is in sync with package.json so that reproducing the issue is accurate.

Your ui-kit-core-core project contains ng-package.json, which points to src/index.ts. That makes this project have a duplicate entry point with the same TS path alias. If you remove the ng-package.json, you will see the expected error.

@nikbabchenko
Copy link
Author

nikbabchenko commented Apr 18, 2023

@meeroslav, need to mention, the ' ui-kit-core-core' has been generated via NX console.
So, still seems like a bug.

btw, @meeroslav, since the library is buildable. It needs it's own ng-package.json, correct?
Basically, it's the main point of this bug.

In v13 of nx-workspace it works as expected.

btw, could you still build the library after removing 'ng-package.json'?

@meeroslav
Copy link
Contributor

meeroslav commented Apr 18, 2023

You are correct. Sorry for being so fast with my conclusions.

v13 ignored secondary entry points, so this was treated as any other code. Unfortunately, the latest fix does not consider the buildable libs to have also ng-package.json.

@meeroslav meeroslav reopened this Apr 18, 2023
@nikbabchenko
Copy link
Author

nikbabchenko commented Apr 18, 2023

Thanks for tracking this one, because having the NX in order to control boundaries in combination with 'Webstorm' or 'Idea' adds issues with circular imports the library on itself. (Idea and Webstorm auto-import the library itself. For sure it's configurable and could be fixed, but eslint accepts such imports currently)

NX doesn't handle this scenario. So, basically you have to additionally add lint rules to handle self imports.

@meeroslav
Copy link
Contributor

I have created the fix. Unfortunately, you will have to be a bit more patient until it's released.

Thank you again for reporting it.

@wSedlacek
Copy link
Contributor

@meeroslav I noticed a regression after #16367.

In my case I have a buildable angular library which has secondary entry points which import the primary entry point.

@flagship-create/async-store -> @flagship-create/async-store/indexeddb

When it tries to check the import of @flagship-create/async-store it is prevented from reading the ng-package.json at the project root and thus doesn't consider it a secondary entry point (which technically it is not) but it should still be valid for a secondary entrypoint to import the primary entrypoint so long as there isn't a cycle.

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2023
@meeroslav
Copy link
Contributor

Hey @wSedlacek sorry for the late reply. Please create a separate issue and link it to this one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants