nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.39k stars 2.33k forks source link

Linting fails with spurious TypeScript type-checker error after upgrade to Nx 19.1.0 ... 19.5.3 #26597

Closed KeithGillette closed 2 months ago

KeithGillette commented 3 months ago

Current Behavior

Running nx lint projectName in a workspace upgraded from 19.0.8 to 19.1.0, 19.3.0, 19.3.1, 19.4.0, 19.4.1, 19.4.2, 19.4.3, 19.4.4, 19.5.0, 19.5.1, 19.5.2, or 19.5.3 generates the following error for each project:

Error: You have attempted to use the lint rule rxjs/no-ignored-notifier which requires the full TypeScript type-checker to be available, but you do not have `parserOptions.project` configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your project ESLint config `apps/projectName/.eslintrc.json`

Expected Behavior

nx lint projectName continues to run without error

GitHub Repo

No response

Steps to Reproduce

nx migrate latest
npx nx migrate --run-migrations
nx lint projectName

Nx Report

Node   : 20.10.0
OS     : darwin-arm64
npm    : 10.2.3

nx             : 19.3.0
@nx/js         : 19.3.0
@nx/jest       : 19.3.0
@nx/linter     : 19.3.0
@nx/eslint     : 19.3.0
@nx/workspace  : 19.3.0
@nx/angular    : 19.3.0
@nx/cypress    : 19.3.0
@nx/devkit     : 19.3.0
@nx/node       : 19.3.0
@nrwl/tao      : 19.3.0
@nx/web        : 19.3.0
@nx/webpack    : 19.3.0
typescript     : 5.4.5
---------------------------------------
Community plugins:
apollo-angular : 7.0.2

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

Project .eslint.json files already included references to tsconfig.json in their overrides.parserOptions.project array:


{
  "extends": "../../.eslintrc.json",
  "ignorePatterns": [
    "!**/*",
    "environment.*.ts"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "createDefaultProgram": true,
        "project": [
          "apps/projectName/tsconfig.app.json",
          "apps/projectName/tsconfig.spec.json"
        ]
      }
    }
  ]
}
EugeneKruglei commented 3 months ago

same issue... also tried to replace parserOptions project to : "parserOptions": { "project": ["apps/projectName/tsconfig.json"] },

  and got new error:
  _ NX   Error while loading rule '@angular-eslint/template/banana-in-box': You have used a rule which requires '@angular-eslint/template-parser' to be used as the 'parser' in your ESLint config.

_

leosvelperez commented 2 months ago

Thanks for reporting this!

Unfortunately, I can't reproduce the issue. Based on the provided information, I tried the following:

  1. Created workspace with Nx 19.0.8:

      npx -y create-nx-workspace@19.0.8 --nx-cloud=skip --pm=npm issue-26597
    
       NX   Let's create a new workspace [https://nx.dev/getting-started/intro]
    
      ✔ Which stack do you want to use? · angular
      ✔ Integrated monorepo, or standalone project? · integrated
      ✔ Application name · app1
      ✔ Which bundler would you like to use? · esbuild
      ✔ Default stylesheet format · css
      ✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? · No
      ✔ Test runner to use for end to end (E2E) tests · cypress
    
       NX   Creating your v19.0.8 workspace.
    
      ...
  2. Installed eslint-plugin-rxjs and configured the rule in the apps/app1/.eslintrc.json file
  3. Migrated to the latest version of Nx (19.5.1 at the time of writing)
  4. Ran npx nx lint app1 successfully

You can check the steps in each commit of the following repo: https://github.com/leosvelperez/issue-26597.

Given we can't reproduce the issue, please provide a repo where we can reproduce it so we can troubleshoot and fix it.

KeithGillette commented 2 months ago

Thank you for attempting to reproduce this issue we are experiencing, @leosvelperez. I am attempting to reproduce the issue in a clone of your repository modified to with our ESLint and TypeScript configurations but have yet to be able to do so. Our project is using the @nx/linter:eslint executor but we still get the same error switching to @nx/eslint:lint. We have the rules from eslint-plugin-rxjs defined in the workspace .eslintrc.json but trying that in the issue-26597 repo doesn't cause the error. Any pointers on getting additional nx lint diagnostics beyond the --verbose flag would be appreciated.

leosvelperez commented 2 months ago

You could try running:

DEBUG=eslint* nx lint projectName

You could also try running with ESLint directly to see if there's an issue with the executor itself or if it's some weird configuration issue:

cd path/to/project/root
npx eslint . --debug

Both options will print a lot of information. The @nx/eslint:lint executor only prints that message when ESLint itself throws that same error (https://github.com/nrwl/nx/blob/master/packages/eslint/src/executors/lint/lint.impl.ts#L104-L108). All the executor does is gather some extra information to try to provide a more helpful message than the default message thrown by ESLint.

KeithGillette commented 2 months ago

Thank you for the troubleshooting guidance, @leosvelperez. Unfortunately, I am still struggling to identify the source of the problem in our project. Running ESLint directly with npx eslint . --debug fails, as we are using .eslintrc.json configurations:

Oops! Something went wrong! :(

ESLint: 9.7.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

I tried nx g @nx/eslint:convert-to-flat-config but it only converts the workspace .eslintrc.json, not the project .eslint.json files, so the resulting configuration is broken.

What I find confusing when running DEBUG=eslint* nx lint projectName is that the tail end of the output shows the very tsconfig files it's claiming we don't have:

  eslint:linter An error occurred while traversing +2s
  eslint:linter Filename: /path/to/apps/projectName/jest.config.ts +0ms
  eslint:linter Parser Options: {
  createDefaultProgram: true,
  project: [
    'apps/projectName/tsconfig.app.json',
    'apps/projectName/tsconfig.spec.json'
  ],
  sourceType: 'module',
  ecmaVersion: 11,
  ecmaFeatures: { globalReturn: false }
} +0ms
  eslint:linter Parser Path: /path/to/node_modules/@typescript-eslint/parser/dist/index.js +0ms
  eslint:linter Settings: {} +0ms

Error: You have attempted to use the lint rule "rxjs/no-ignored-notifier" which requires the full TypeScript type-checker to be available, but you do not have "parserOptions.project" configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your ESLint config "apps/projectName/.eslintrc.json"
Occurred while linting /path/to/apps/projectName/jest.config.ts

Please see https://nx.dev/recipes/tips-n-tricks/eslint for full guidance on how to resolve this issue.
leosvelperez commented 2 months ago

You just provided the missing piece to reproduce the issue: you're using ESLint v9.

Unfortunately, the issue is caused by eslint-plugin-rxjs depending on eslint-etc, which depends on @typescript-eslint/experimental-utils. This is an old package and doesn't support a change made in ESLint related to the parser services. The parserServices was moved from the ESLint rule context object to the nested sourceCode object (context.parserServices => context.sourceCode.parserServices).

There's an open PR to use an updated version of @typescript-eslint/utils instead of the current @typescript-eslint/experimental-utils but it hasn't been merged: https://github.com/cartant/eslint-etc/pull/13.

I'm closing this issue since we cannot solve it on the Nx side. You can report it to the eslint-plugin-rxjs repository. Hopefully, the linked PR above will be merged soon, or if they have been blocked by that dependency for too long, they could consider removing it.

KeithGillette commented 2 months ago

Thank you for the fast and detailed reply, @leosvelperez. If I downgrade to eslint@8.57.0, then nx migrate latest, the parserOptions errors do not appear when linting. However, there's one thing I don't understand about your explanation of the problem: If the issue is an incompatibility between eslint-plugin-rxjs and ESLint v9, why have both been working in our project on Nx versions less than 19.1.0? It was only with attempts to upgrade to Nx v19.1.0 and later that we received this message. eslint@9.7.0 and eslint-plugin-rxjs@5.0.3 work fine under nx@19.0.8.

leosvelperez commented 2 months ago

That is a good point. I took another look, and it's because in 19.1.0, we added some level of support for ESLint v9. As part of that, we extended the range of the ESLint dependency to correctly include v9 (https://github.com/nrwl/nx/commit/8cfc0a0c08fad7dd0af42e96a2ef26a377e4e8f5#diff-83ca08b9de9168d7d59366dc40f4e5a4590a7645790563ad6c9fbb9699e053a1). So, before that, when using ESLint v9 with the @nx/eslint package depending only on v8, npm would resolve ESLint v8 under the @nx/eslint package. So, when running the lint executor, this would actually use ESLint v8 to run the task, even though you had ESLint v9 installed at the root.

So, before 19.1.0, you were effectively using ESLint v8 when running you lint tasks. After 19.1.0, you're now correctly using the ESLint v9 version you have installed and this one is not supported by eslint-plugin-rxjs, hence the issue.

github-actions[bot] commented 1 month ago

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.