Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint cli: TypeError: Error while loading rule '@nx/enforce-module-boundaries': Cannot read properties of undefined (reading 'keyword') #20752

Closed
1 of 4 tasks
gergelyszerovay opened this issue Dec 13, 2023 · 11 comments · Fixed by #21201
Assignees
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug

Comments

@gergelyszerovay
Copy link

gergelyszerovay commented Dec 13, 2023

Current Behavior

I run pnpm exec eslint src/**/*.ts modules/**/*.ts on a simple workspace based on https://nx.dev/getting-started/tutorials/angular-standalone-tutorial, and the command fails with the following error, if there is no cached graph in the .nx dir:

Oops! Something went wrong! :(

ESLint: 8.48.0

TypeError: Error while loading rule '@nx/enforce-module-boundaries': Cannot read properties of undefined (reading 'keyword')  
Occurred while linting C:\Users\sg\Documents\VSCode\nx17-eslint-issue\src\app\app.component.spec.ts
    at ensureGlobalProjectGraph (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected]_@[email protected]_@type_yt4xlg4c76xjsbszsarj5ttuue\node_modules\@nx\eslint-plugin\src\utils\project-graph-utils.js:35:51)
...

Expected Behavior

The eslint cli should work. I have similar issues with PyCharm's built-in eslint functionality.

pnpm exec nx run-many -t lint works as expected.

GitHub Repo

https://github.com/gergelyszerovay/nx17-eslint-issue/

Steps to Reproduce

  1. run pnpm exec nx reset
  2. run pnpm exec eslint src/**/*.ts modules/**/*.ts

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 18.16.0
   OS     : win32-x64
   pnpm   : 8.12.0
   
   nx                 : 17.2.4
   @nx/js             : 17.2.4
   @nx/jest           : 17.2.4
   @nx/linter         : 17.2.4
   @nx/eslint         : 17.2.4
   @nx/workspace      : 17.2.4
   @nx/angular        : 17.2.4
   @nx/cypress        : 17.2.4
   @nx/devkit         : 17.2.4
   @nx/eslint-plugin  : 17.2.4
   @nrwl/tao          : 17.2.4
   @nx/web            : 17.2.4
   @nx/webpack        : 17.2.4
   typescript         : 5.2.2

Failure Logs

Oops! Something went wrong! :(

ESLint: 8.48.0

TypeError: Error while loading rule '@nx/enforce-module-boundaries': Cannot read properties of undefined (reading 'keyword')  
Occurred while linting C:\Users\sg\Documents\VSCode\nx17-eslint-issue\src\app\app.component.spec.ts
    at ensureGlobalProjectGraph (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected]_@[email protected]_@type_yt4xlg4c76xjsbszsarj5ttuue\node_modules\@nx\eslint-plugin\src\utils\project-graph-utils.js:35:51)
    at readProjectGraph (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected]_@[email protected]_@type_yt4xlg4c76xjsbszsarj5ttuue\node_modules\@nx\eslint-plugin\src\utils\project-graph-utils.js:46:5)
    at create (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\@[email protected]_@[email protected]:134:137)
    at Object.create (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@typescript-eslint\utils\dist\eslint-utils\RuleCreator.js:38:20)
    at createRuleListeners (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\e[email protected]\node_modules\eslint\lib\linter\linter.js:870:21)
    at C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\e[email protected]\node_modules\eslint\lib\linter\linter.js:1040:110
    at Array.forEach (<anonymous>)
    at runRules (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\e[email protected]\node_modules\eslint\lib\linter\linter.js:977:34)
    at Linter._verifyWithoutProcessors (C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\e[email protected]\node_modules\eslint\lib\linter\linter.js:1330:31)
    at C:\Users\sg\Documents\VSCode\nx17-eslint-issue\node_modules\.pnpm\e[email protected]\node_modules\eslint\lib\linter\linter.j ELIFECYCLE  Command failed with exit code 2.

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

The users in this discussion have the same issue: #20194

@ksdc-grantw
Copy link

Got the same error myself in VSCode. easiest solution was to reload the window (or restart vscode) and the service started back up without a problem.

@lazybobcat
Copy link

Got the same error myself in VSCode. easiest solution was to reload the window (or restart vscode) and the service started back up without a problem.

Restarting VSCode did not solve the issue for me, I had to remove the rule altogether (which I would prefer not to do) as a temporary solution in order to get rid of the error and have eslint running in VSCode

@Moeface
Copy link

Moeface commented Dec 19, 2023

This error also occurs for us when running the lint step in our continuous integration platform (CircleCI)

@bratconnex
Copy link

I have the same issue locally after upgrading to nx17! Any restarting etc will not fix the issue for me, but for others in my team it did end up fixing it.

@AgentEnder AgentEnder added the scope: linter Issues related to Eslint support in Nx label Dec 21, 2023
@blackholegalaxy
Copy link

blackholegalaxy commented Jan 3, 2024

Please note I also encounter this problem on our project. Locally it works perfectly. In a github CI context, we encounter the error.

"lint": {
      "executor": "@nx/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["libs/layout/**/*.ts", "libs/layout/**/*.html"]
      }
    }
NX   Running target lint for 3 projects:
    - layout
    - x
    - y
 
> nx run matero:lint
Linting "layout"...
 >  NX   Error while loading rule '@nx/enforce-module-boundaries': Cannot read properties of undefined (reading 'keyword')
   Occurred while linting /home/runner/work/starter/libs/layout/src/index.ts
   Pass --verbose to see the stacktrace.

Was working perfectly on 16.10.0

@howdysuraj
Copy link

Any update on fixing this issue ?

@HoracePGreeley
Copy link

I have the same issue locally with VSCode and Angular 17

@yordan-kanchelov
Copy link

i can reproduce the same issue with mac setup + pnpm

@medv
Copy link

medv commented Jan 16, 2024

i can reproduce the same issue with mac setup + pnpm

Same here with this combination, surprising since it's going great on a different machine.

@meeroslav meeroslav self-assigned this Jan 18, 2024
@meeroslav
Copy link
Contributor

Thank you all for chiming in. I will look at it now.

The rule, unfortunately, does not work unless there is a graph available since it depends on the graph information. But it should not block the eslint either.

RasmusKjeldgaard added a commit to kirbydesign/designsystem that referenced this issue Jan 22, 2024
Workaround needed because of nrwl/nx#20752
RasmusKjeldgaard added a commit to kirbydesign/designsystem that referenced this issue Jan 22, 2024
Workaround needed because of nrwl/nx#20752
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.