question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESlint rule @nrwl/nx/enforce-module-boundaries causing issues with application libraries (nestjs)

See original GitHub issue

Current 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

image

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:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
chrismcleodcommented, Sep 9, 2021

@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.

0reactions
chrismcleodcommented, Sep 9, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nestjs eslint does not work properly + vscode Eslint configured ...
Current Behavior yarn run lint which executes nx run-many --target=lint --all --parallel --fix fails to run eslint-rules.
Read more >
I wrote an eslint module for checking NestJS modules and ...
I've described the rules below. Let me know if you try it out and have any issues or suggestions! Why create an eslint...
Read more >
Monorepo - CLI | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines ...
Read more >
node.js - no-unused-var eslint for modules and types in nestsjs
I believe this comes from this issue in typescript-eslint. Only workaround currently is to not use that specific rule.
Read more >
API with NestJS #61. Dealing with circular dependencies
Detecting circular dependencies using ESLint. The provided code example makes it very obvious that there is a circular dependency between files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found