Skip to content

Automatic ng add of @angular-eslint/schematics still throws the first time based on missing lint target #22937

@JamesHenry

Description

@JamesHenry

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Unknown

Description

When following the libraries tutorial, running ng lint will throw the first time you run it, but pass the second time.

🔬 Minimal Reproduction

Follow the steps outlined here taken from the creating libraries tutorial on angular.io:
angular-eslint/angular-eslint#917

🔥 Exception or Error




An unhandled exception occurred: Project target does not exist.
See "/private/var/folders/zs/vbyzg7s52n9flpbjxjc_xplc0000gn/T/ng-XzDOA6/angular-errors.log" for further details.

[error] Error: Project target does not exist.
    at findProjectTarget (/Users/james/Repos/tmp/new-workspace/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:53:15)
    at Object.getBuilderName (/Users/james/Repos/tmp/new-workspace/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:66:46)
    at WorkspaceNodeModulesArchitectHost.getBuilderNameForTarget (/Users/james/Repos/tmp/new-workspace/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:105:35)
    at LintCommand.runSingleTarget (/Users/james/Repos/tmp/new-workspace/node_modules/@angular/cli/models/architect-command.js:246:55)
    at LintCommand.runArchitectTarget (/Users/james/Repos/tmp/new-workspace/node_modules/@angular/cli/models/architect-command.js:299:35)
    at LintCommand.run (/Users/james/Repos/tmp/new-workspace/node_modules/@angular/cli/models/architect-command.js:240:27)
    at LintCommand.validateAndRun (/Users/james/Repos/tmp/new-workspace/node_modules/@angular/cli/models/command.js:136:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runCommand (/Users/james/Repos/tmp/new-workspace/node_modules/@angular/cli/models/command-runner.js:228:24)
    at async default_1 (/Users/james/Repos/tmp/new-workspace/node_modules/@angular/cli/lib/cli/index.js:70:31)

🌍 Your Environment



Angular CLI: 13.3.1
Node: 16.13.2
Package Manager: npm 8.3.0
OS: darwin arm64

Angular: 13.3.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1303.1
@angular-devkit/build-angular   13.3.1
@angular-devkit/core            13.3.1
@angular-devkit/schematics      13.3.1
@schematics/angular             13.3.1
ng-packagr                      13.3.0
rxjs                            7.5.5
typescript                      4.6.3

Anything else relevant?

Full output from ng lint my-lib onwards, showing the error and subsequent successful run:

~/Repos/tmp/new-workspace   ⬢  16.13.2                                                                                                                                                                                            main
❯ ng lint my-lib                                                                                                                                                                                                                    

Cannot find "lint" target for the specified project.

You should add a package that implements linting capabilities.

For example:
  ng add @angular-eslint/schematics

Would you like to add ESLint now? Yes
ℹ Using package manager: npm
✔ Found compatible package version: @angular-eslint/schematics@13.2.0.
✔ Package information loaded.

The package @angular-eslint/schematics@13.2.0 will be installed and executed.
Would you like to proceed? Yes
✔ Package successfully installed.

    All @angular-eslint dependencies have been successfully installed 🎉

    Please see https://github.com/angular-eslint/angular-eslint for how to add ESLint configuration to your project.

    We detected that you have a single project in your workspace and no existing linter wired up, so we are configuring ESLint for you automatically.

    Please see https://github.com/angular-eslint/angular-eslint for more information.

CREATE .eslintrc.json (984 bytes)
CREATE projects/my-lib/.eslintrc.json (842 bytes)
UPDATE package.json (1482 bytes)
UPDATE angular.json (1457 bytes)
✔ Packages installed successfully.
An unhandled exception occurred: Project target does not exist.
See "/private/var/folders/zs/vbyzg7s52n9flpbjxjc_xplc0000gn/T/ng-XzDOA6/angular-errors.log" for further details.


~/Repos/tmp/new-workspace   ⬢  16.13.2                                                                                                                                                                                            main
❯ ng lint my-lib                                                                                                                                                                                                              

Linting "my-lib"...

/Users/james/Repos/tmp/new-workspace/projects/my-lib/src/lib/my-lib.component.ts
  17:3  error  Lifecycle methods should not be empty  @angular-eslint/no-empty-lifecycle-method

✖ 1 problem (1 error, 0 warnings)

Lint errors found in the listed files.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions