ESlint rule @nrwl/nx/enforce-module-boundaries causing issues with application libraries (nestjs)
See original GitHub issueCurrent Behavior
When I create more than one library with: (using @nrwl/nestjs
collection by default)
nx g library my-lib --directory=my-app
nx g library my-second-lib --directory=my-app
and then import those somewhere inside my-app
, a red squiggle appears with the following error:
Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "@tests/my-app/my-second-lib
It feels very strange, because the first library didn’t cause issues. It only happens when another one is generated. I didn’t find any differences in configuration in workspace.json
or typescript.base.json
. I am completely at a loss here 😦
It’s as if eslint thinks the library is in the same project directory as my-app, which it clearly isn’t.
Expected Behavior
I expect to be able to import all libraries for the app in the app.
Steps to Reproduce
Clone this repo: https://github.com/svanda-navisys/nx-eslint-bug-reporoduction, install dependencies, run the above commands and try importing the created libraries anywhere in my-app
Or swich to the bug
branch and see that the second library import in my-app/src/app/app.module.ts
causes the error
Environment
Visual Studio Code on Windows 10
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
@svanda-navisys i deleted node_modules/.cache/nx and it seems to work for me now. After digging into the eslint rule it looked like for whatever reason, the eslint rule was referencing a cached project graph which did not include my library. The end result is that the logic of the eslint-rule ends up thinking your library file is in the app module.
@AgentEnder
I also got this issue and it goes away if I change the typescript alias to remove the dash
in tsconfig.base.json aliases: “@company/my-app/bubblegum”: [“libs/my-app/bubblegum/src/index.ts”] <- I get the OP error when importing in the app
“@company/myapp/bubblegum”: [“libs/my-app/bubblegum/src/index.ts”] <- no error
im guessing it has something to do with the fact that nx slugifies / in nested lib directories to hyphens.