nx icon indicating copy to clipboard operation
nx copied to clipboard

Nx 17 - Buildable Angular libs fail lint upon generation with `The "tslib" package is not used by "my-lib" project`

Open abaran30 opened this issue 1 year ago • 2 comments
trafficstars

Current Behavior

When generating a buildable Angular library, lint for the new library fails right away with the following error:

  9:5  error  The "tslib" package is not used by "my-lib" project  @nx/dependency-checks

Expected Behavior

Newly generated Angular libraries (buildable or not) should not fail lint.

GitHub Repo

https://github.com/abaran30/nx-angular-playground

Steps to Reproduce

  1. Clone the above repo; gh repo clone abaran30/nx-angular-playground
  2. npm ci
  3. Generate a new buildable Angular library: npx nx generate @nx/angular:library --name=my-lib --buildable=true --projectNameAndRootFormat=derived --standalone=false --style=none --no-interactive
  4. Run npx nx run my-lib:lint

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 18.15.0
   OS     : darwin-arm64
   npm    : 9.5.0

   nx                 : 17.1.2
   @nx/js             : 17.1.2
   @nx/jest           : 17.1.2
   @nx/linter         : 17.1.2
   @nx/eslint         : 17.1.2
   @nx/workspace      : 17.1.2
   @nx/angular        : 17.1.2
   @nx/cypress        : 17.1.2
   @nx/devkit         : 17.1.2
   @nx/eslint-plugin  : 17.1.2
   @nrwl/tao          : 17.1.2
   @nx/web            : 17.1.2
   @nx/webpack        : 17.1.2
   typescript         : 5.2.2

Failure Logs

9:5  error  The "tslib" package is not used by "my-lib" project  @nx/dependency-checks

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Lint errors found in the listed files.

Package Manager Version

No response

Operating System

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

Additional Information

As shown in the failure logs, the lint error is fixable with the --fix option. The fixer removes tslib from the the library's package.json dependencies. Should tslib not be included upon generation?

abaran30 avatar Jan 05 '24 14:01 abaran30

Similarly I get an error during lint if I don't utilize @angular/core in a utility library.

6:3   error    The "@angular/core" package is not used by "my-util-lib" project.   @nx/dependency-checks

My organization uses these Angular libraries to hold utilities - some of which might just be plain TypeScript functions & could contain shared Angular Pipes for instance.

Is the expected behavior here to remove @angular/core from the library's package.json until an Angular class is used? That seems kinda annoying to do if I wanted to add an Angular Pipe to a utility library that previously only contained a TypeScript helper function.

andy-bond avatar Jan 05 '24 20:01 andy-bond

same behavior with latest nx

angular monorepo project with generated publishable library

9:5 error The "tslib" package is not used by "mylibpublishable" project @nx/dependency-checks

>  NX   Report complete - copy this into the issue template

   Node   : 18.18.0
   OS     : win32-x64
   npm    : 10.2.0

   nx                 : 17.3.0
   @nx/js             : 17.3.0
   @nx/jest           : 17.3.0
   @nx/linter         : 17.3.0
   @nx/eslint         : 17.3.0
   @nx/workspace      : 17.3.0
   @nx/angular        : 17.3.0
   @nx/cypress        : 17.3.0
   @nx/devkit         : 17.3.0
   @nx/eslint-plugin  : 17.3.0
   @nrwl/tao          : 17.3.0
   @nx/web            : 17.3.0
   @nx/webpack        : 17.3.0
   typescript         : 5.3.3

alexanderPastornicky avatar Jan 31 '24 13:01 alexanderPastornicky

Hey! It looks your GH Repo is 404ing. Could you provide me with another repo so that I can investigate further?

Coly010 avatar May 15 '24 14:05 Coly010

@Coly010 my apologies; did a repo cleanup and forgot I had one linked to this issue 😅.

I updated the issue description with a new repo; updated to latest Nx and issue is still reproducible.

abaran30 avatar May 15 '24 16:05 abaran30

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[bot] avatar Jun 17 '24 00:06 github-actions[bot]