nrwl / nx

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

enforce-module-boundaries mistakes the app name in a lib prefix as the app directory #8319

Closed qortex closed 2 years ago

qortex commented 2 years ago

Current Behavior

I use the architecture advised in the angular architecture book by the Nx team:

apps/
    booking/
    check-in/
  libs/
    booking/                 <---- grouping folder
      feature-shell/         <---- library

    check-in/
      feature-shell/

    shared/                  <---- grouping folder
      data-access/           <---- library

      seatmap/               <---- grouping folder
        data-access/         <---- library
        feature-seatmap/     <---- library

Then I use the enforce-module-boundaries to make sure libs are properly imported.

But from the booking app, if I import '@myproject/booking/feature-shell, I get this error:

Linting error with eslint (@nrwl/nx/enforce-module-boundaries): Projects should use relative imports to import from other files within the same project.

I understand it's because @myproject/booking is misinterpreted as pointing to apps/booking, where it's not the case, it's just that the schematics builder also uses @myproject/booking to point to libs libs.

Indeed, changing the name of the lib by hand in tsconfig.base to @myproject/libs/booking/feature-shell for example fixes the issue. But I would like to stick to out-of-the-box naming because otherwise it defeats the use of the schematics builder.

Expected Behavior

I would expect the linting rule to work out of the box with the given example.

I don't know if it's a regression (probably, since the book was written?)

Environment

 NX  Report complete - copy this into the issue template

  Node : 14.17.0
  OS   : linux x64
  yarn : 1.22.17

  nx : 13.4.1
  @nrwl/angular : 13.4.1
  @nrwl/cli : 13.4.1
  @nrwl/cypress : 13.4.1
  @nrwl/devkit : 13.4.1
  @nrwl/eslint-plugin-nx : 13.4.1
  @nrwl/express : undefined
  @nrwl/jest : 13.4.1
  @nrwl/linter : 13.4.1
  @nrwl/nest : undefined
  @nrwl/next : undefined
  @nrwl/node : undefined
  @nrwl/nx-cloud : undefined
  @nrwl/react : undefined
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.4.1
  @nrwl/web : undefined
  @nrwl/workspace : 13.4.1
  @nrwl/storybook : 13.4.1
  @nrwl/gatsby : undefined
  typescript : 4.5.4
  rxjs : 7.4.0
  ---------------------------------------
  Community plugins:
     @angular/animations: 13.1.1
     @angular/common: 13.1.1
     @angular/compiler: 13.1.1
     @angular/core: 13.1.1
     @angular/forms: 13.1.1
     @angular/platform-browser: 13.1.1
     @angular/platform-browser-dynamic: 13.1.1
     @angular/router: 13.1.1
     @ngneat/transloco: 3.1.1
     @ngrx/component: 13.0.2
     @ngrx/component-store: 13.0.2
     @ngrx/effects: 13.0.2
     @ngrx/entity: 13.0.2
     @ngrx/router-store: 13.0.2
     @ngrx/store: 13.0.2
     apollo-angular: 2.6.0
     @angular-devkit/build-angular: 13.1.2
     @angular/cli: 13.1.2
     @angular/compiler-cli: 13.1.1
     @angular/language-service: 13.1.1
     @ngneat/tailwind: 7.0.3
     @ngrx/schematics: 13.0.2
     @ngrx/store-devtools: 13.0.2
     @storybook/angular: 6.4.9
qortex commented 2 years ago

Well, just an ESLint server reset fixed the issue, so it was just a temporary glitch somehow.

qortex commented 2 years ago

Hum, happens again in another place (wrongly detects circular dependency because it thinks it refers to the main app but it's a lib).

Any pointer as to how to debug & workaround?

qortex commented 2 years ago

Disappeared again after several resets. Definitely something going on with caching or something.

vzakanj commented 2 years ago

I have this exact same problem using WebStorm and it seems to be a caching issue similar to the one in #8313.

Can confirm that the following suggestion in that issue works for me https://github.com/nrwl/nx/issues/8313#issuecomment-1008774008

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.