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

Cannot find module '@nrwl/linter/package.json' when running lint #20057

Closed
aikrez opened this issue Nov 6, 2023 · 18 comments
Closed

Cannot find module '@nrwl/linter/package.json' when running lint #20057

aikrez opened this issue Nov 6, 2023 · 18 comments
Assignees
Labels

Comments

@aikrez
Copy link

aikrez commented Nov 6, 2023

Current Behavior

An error is shown when running lint command

 Cannot find module '@nrwl/linter/package.json'
   Require stack:
   - <path>\node_modules\nx\src\utils\package-json.js
   - <path>\node_modules\nx\src\utils\package-manager.js
   - <path>\node_modules\nx\bin\init-local.js
   - <path>\node_modules\nx\bin\nx.js
   Pass --verbose to see the stacktrace.

Expected Behavior

No error

GitHub Repo

No response

Steps to Reproduce

  1. upgraded from 16.6.0 to 17.0.3
  2. run nx affected -t lint

Nx Report

Node   : 18.16.0
   OS     : win32-x64
   yarn   : 1.22.19

   nx                 : 17.0.3
   @nx/js             : 17.0.3
   @nx/jest           : 17.0.3
   @nx/linter         : 17.0.3
   @nx/eslint         : 17.0.3
   @nx/workspace      : 17.0.3
   @nx/angular        : 17.0.3
   @nx/cypress        : 17.0.3
   @nx/devkit         : 17.0.3
   @nx/eslint-plugin  : 17.0.3
   @nx/node           : 17.0.3
   @nx/plugin         : 17.0.3
   @nx/storybook      : 17.0.3
   @nrwl/tao          : 17.0.3
   @nx/web            : 17.0.3
   @nx/webpack        : 17.0.3
   typescript         : 5.1.6
   ---------------------------------------
   Community plugins:
   @compodoc/compodoc         : 1.1.21
   @ng-bootstrap/ng-bootstrap : 14.1.1
   @ngrx/component-store      : 16.1.0
   @ngrx/effects              : 16.1.0
   @ngrx/router-store         : 16.1.0
   @ngrx/schematics           : 16.1.0
   @ngrx/store                : 16.1.0
   @ngrx/store-devtools       : 16.1.0
   @storybook/angular         : 7.2.1
   ---------------------------------------

Failure Logs

Cannot find module '@nrwl/linter/package.json'
   Require stack:
   - <path>\node_modules\nx\src\utils\package-json.js
   - <path>\node_modules\nx\src\utils\package-manager.js
   - <path>\node_modules\nx\bin\init-local.js
   - <path>\node_modules\nx\bin\nx.js
   Pass --verbose to see the stacktrace.


### Package Manager Version

_No response_

### Operating System

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

### Additional Information

_No response_
@jaibeales
Copy link

We are getting the same thing.

@AgentEnder AgentEnder added blocked: more info needed scope: linter Issues related to Eslint support in Nx labels Nov 6, 2023
@AgentEnder
Copy link
Member

What does the project.json file look like for the project that is erroring?

@aikrez
Copy link
Author

aikrez commented Nov 7, 2023

I do not see on which project the command is giving an errror
npx nx affected -t lint --verbose

(we still have a workspace.json but that is for a custom script that needs to be refactored)


   Nx no longer reads configuration from workspace.json.
   Run "nx g @nx/workspace:fix-configuration" to split workspace.json into individual project.json files.


 >  NX   Affected criteria defaulted to --base=master --head=HEAD


 >  NX   Unable to resolve @nrwl/linter:eslint.

   Cannot find module '@nrwl/linter/package.json'
   Require stack:
   - <repo_path>\node_modules\nx\src\utils\package-json.js
   - <repo_path>\node_modules\nx\src\utils\package-manager.js
   - <repo_path>\node_modules\nx\bin\init-local.js
   - <repo_path>\node_modules\nx\bin\nx.js

Error: Unable to resolve @nrwl/linter:eslint.
Cannot find module '@nrwl/linter/package.json'
Require stack:
- <repo_path>\node_modules\nx\src\utils\package-json.js
- <repo_path>\node_modules\nx\src\utils\package-manager.js
- <repo_path>\node_modules\nx\bin\init-local.js
- <repo_path>\node_modules\nx\bin\nx.js
    at getExecutorInformation (<repo_path>\node_modules\nx\src\command-line\run\executor-utils.js:53:15)
    at getExecutorForTask (<repo_path>\node_modules\nx\src\tasks-runner\utils.js:187:56)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getCustomHasher (<repo_path>\node_modules\nx\src\tasks-runner\utils.js:191:22)
    at async <repo_path>\node_modules\nx\src\hasher\hash-task.js:11:30
    at async Promise.all (index 43)
    at async hashTasksThatDoNotDependOnOutputsOfOtherTasks (<repo_path>\node_modules\nx\src\hasher\hash-task.js:10:30)
    at async invokeTasksRunner (<repo_path>\node_modules\nx\src\tasks-runner\run-command.js:136:5)
    at async <repo_path>\node_modules\nx\src\tasks-runner\run-command.js:91:24
    at async handleErrors (<repo_path>\node_modules\nx\src\utils\params.js:9:16)```

The only thing that is changed in the project.json
![image](https://github.com/nrwl/nx/assets/8655340/afb58385-fb64-4f8b-a0f2-3ddae83fd1e5)

@aikrez
Copy link
Author

aikrez commented Nov 7, 2023

image

@jaibeales
Copy link

Same with us migration largely did the above to all the project files. This is the output from CI:

 >  NX   Unable to resolve @nrwl/linter:eslint.

   Cannot find module '@nrwl/linter/package.json'
   Require stack:
   - /runner/_work/frontend/frontend/node_modules/nx/src/utils/package-json.js
   - /runner/_work/frontend/frontend/node_modules/nx/src/utils/package-manager.js
   - /runner/_work/frontend/frontend/node_modules/nx/bin/init-local.js
   - /runner/_work/frontend/frontend/node_modules/nx/bin/nx.js
   Pass --verbose to see the stacktrace.

@underfisk
Copy link

I'm also experiencing the same issue, locally the Linting works just fine but in CI it fails to load the resolve
NX Failed to load plugin '@nx' declared in 'packages/jobs/.eslintrc.json » ../../.eslintrc.json#overrides[1]': Unexpected identifier

@HerrBertling
Copy link

I'm running into the same issue. Thanks for the screenshot, @aikrez – I checked and apparently the executor was switched for projects in the apps folder but not for the ones in the libs folder.

For my apps, I also have "executor": "@nrwl/linter:eslint", for the lint target. For the libs folder, each project has "executor": "@nx/eslint:lint", – changing the former to @nx/eslint:lint executor fixes it.

Question is where this is coming from 😅

@aikrez
Copy link
Author

aikrez commented Nov 13, 2023

updated to 17.1.1 and still the same error

>  NX   Report complete - copy this into the issue template

   Node   : 18.16.0
   OS     : win32-x64
   yarn   : 1.22.19

   nx                 : 17.1.1
   @nx/js             : 17.1.1
   @nx/jest           : 17.1.1
   @nx/linter         : 17.1.1
   @nx/eslint         : 17.1.1
   @nx/workspace      : 17.1.1
   @nx/angular        : 17.1.1
   @nx/cypress        : 17.1.1
   @nx/devkit         : 17.1.1
   @nx/eslint-plugin  : 17.1.1
   @nx/node           : 17.1.1
   @nx/plugin         : 17.1.1
   @nx/storybook      : 17.1.1
   @nrwl/tao          : 17.1.1
   @nx/web            : 17.1.1
   @nx/webpack        : 17.1.1
   typescript         : 5.2.2
   ---------------------------------------
   Community plugins:
   @compodoc/compodoc         : 1.1.21
   @ng-bootstrap/ng-bootstrap : 14.1.1
   @ngrx/component-store      : 16.1.0
   @ngrx/effects              : 16.1.0
   @ngrx/router-store         : 16.1.0
   @ngrx/schematics           : 16.1.0
   @ngrx/store                : 16.1.0
   @ngrx/store-devtools       : 16.1.0
   @storybook/angular         : 7.5.3
   ---------------------------------------
   Local workspace plugins:
         @fe-parts/workspace-plugin

I managed to get around it by adding "@nrwl/linter": "^17.1.1" manually to the package.json.
I suppose this should be added by the migration script?

@kschaefe
Copy link

I am getting this issue after migrating to (or rather in the process of migrating to) nx 17.1.2. The linting works if you select a single project. All of the project configurations were updated (via the migration scripts) and the @nrwl/linter does not appear in my code or project files.

The problem arises when I use nx run-many or nx affected and attempt to lint. It appears that some configuration that I don't control is referencing the old linter.

Using the suggestion in the previous comment to manually install @nrwl/linter works around the errors that I am getting using run-many and affected.

@meeroslav meeroslav self-assigned this Nov 16, 2023
@meeroslav
Copy link
Contributor

Hi all,

If you were migrating from the 16.x version to the 17.x you shouldn't have @nrwl/linter in the first place. The migrations in the v17 version provide a migration path from @nx/linter (introduced in v16) to @nx/eslint`.

I'm surprised you still had @nrwl/* packages in v16 repo.

Can someone provide a test repo or a path to reproduce this (without manually messing up the package.json)?

If you need quick fix, just replace all your @nrwl/linter:eslint target executors with @nx/eslint:lint (again this should have been resolved by the migration).

@meeroslav
Copy link
Contributor

@HerrBertling can you paste here the config for one of your apps and libs (ideally before the migration to v17) to see what is different about them that made it break the migration.

@meeroslav
Copy link
Contributor

@aikrez don't install @nrwl/linter. That package is outdated and will be eventually gone in v18.
Fix your executors. Your codebase should not have any reference to @nrwl/* packages.

@aikrez
Copy link
Author

aikrez commented Nov 17, 2023

@aikrez don't install @nrwl/linter. That package is outdated and will be eventually gone in v18. Fix your executors. Your codebase should not have any reference to @nrwl/* packages.

I removed it and indeed 5 of the 180 libs did not migrate correctly where I had to change the lint and jest package.

Had the following @nrwl leftovers:

  • @nrwl/linter:eslint
  • @nrwl/jest:jest
  • @nrwl/js (only in package.json)
  • @nrwl/schematics:component (nx.json)
  • @nrwl/devkit (custom generators)

@meeroslav
Copy link
Contributor

@aikrez can you check got history if this happened during the v16 migration or someone added those later?

@aikrez
Copy link
Author

aikrez commented Nov 17, 2023

Those packages were not added to the package.json (except linter which I added manually). It were remaining executors that used the nrwl packages.

@FabianGosebrink
Copy link
Contributor

FabianGosebrink commented Nov 19, 2023

Had the same problem and manually searched for @nrwl in my codebase. For any reason, one project (out of 134) was not running through the migrations. I adjusted it manually, replaced the builders as @meeroslav said, and I could uninstall @nrwl/linter again. Thanks!

@aikrez aikrez closed this as completed Nov 20, 2023
@HerrBertling
Copy link

HerrBertling commented Nov 20, 2023

@meeroslav It just dawned on me that this might be due to the apps being Remix apps. Maybe they were scaffolded with @nrwl/linter still used in the @nx/remix package? 🤔

I cannot really trace back that traced it back, the apps were scaffolded with "@nx/remix": "^16.8.2",. While I of course found the @nx/remix NPM package, there is no link to a repository that I could check. Also, that @nx/remix package seems to have been updated a month ago to v17. Our scaffolding happened before that. And that package and its apps are probably not part of the normal nx migrate paths.

My best guess is that the @nrwl/linter usages were a leftover from that package scaffolding the two apps we have. The necessary changes then simply were not picked up in the correct places. If you happen to know the location of the @nx/remix package, maybe look there?

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 Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants