nx icon indicating copy to clipboard operation
nx copied to clipboard

@nx/enforce-module-boundaries doesn't work with ESM .js-style imports of TSX files with deep import and aliases

Open lionelhorn opened this issue 1 year ago • 0 comments

Current Behavior

Similar but not exactly to https://github.com/nrwl/nx/issues/15996

Linting fails because @nx/enforce-module-boundaries doesn't properly resolve imports when

  • Tsconfig paths are used
  • Alias has a *
  • Esm import with .js extension are used

Like "@nx-example/shared/product/ui/*": ["libs/shared/product/ui/src/lib/*"],

https://github.com/lionelhorn/nx-examples/blob/530304282599b6f596f9cac04df38b31357f8e4e/tsconfig.base.json#L49

Error: ENOENT: no such file or directory, open '/PROG/_experiments/_nx/nx-examples/libs/shared/product/ui/src/lib/product-price/dummy-component.js'
Occurred while linting C:\PROG\_experiments\_nx\nx-examples\libs\shared\product\ui\src\lib\product-price\some-component.tsx:3
Rule: "@nx/enforce-module-boundaries"
    at Object.openSync (node:fs:603:3)
    at readFileSync (node:fs:471:35)
    at getRelativeImportPath (C:\PROG\_experiments\_nx\nx-examples\node_modules\@nx\eslint-plugin\src\utils\ast-utils.js:101:47)

Expected Behavior

Linting to show @nx/enforce-module-boundaries errors instead of file import resolve issues

GitHub Repo

https://github.com/lionelhorn/nx-examples

Steps to Reproduce

  1. git clone https://github.com/lionelhorn/nx-examples
  2. cd nx-examples
  3. yarn install
  4. cd libs/shared/product/ui
  5. yarn run lint-repro

Nx Report

Node   : 18.18.2
OS     : win32-x64
yarn   : 1.22.22

nx (global)        : 18.0.3
nx                 : 18.1.0-beta.10
@nx/js             : 18.1.0-beta.10
@nx/jest           : 18.1.0-beta.10
@nx/linter         : 18.1.0-beta.10
@nx/eslint         : 18.1.0-beta.10
@nx/workspace      : 18.1.0-beta.10
@nx/angular        : 18.1.0-beta.10
@nx/cypress        : 18.1.0-beta.10
@nx/devkit         : 18.1.0-beta.10
@nx/eslint-plugin  : 18.1.0-beta.10
@nx/react          : 18.1.0-beta.10
@nrwl/tao          : 18.1.0-beta.10
@nx/web            : 18.1.0-beta.10
@nx/webpack        : 18.1.0-beta.10
typescript         : 5.3.3
---------------------------------------
Community plugins:
@ngrx/component-store : 17.0.1
@ngrx/effects         : 17.0.1
@ngrx/entity          : 17.0.1
@ngrx/router-store    : 17.0.1
@ngrx/store           : 17.0.1
@ngrx/store-devtools  : 17.0.1

Failure Logs

No response

Package Manager Version

No response

Operating System

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

Additional Information

No response

lionelhorn avatar Mar 17 '24 20:03 lionelhorn