nrwl / nx

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

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

Closed aikrez closed 11 months ago

aikrez commented 1 year ago

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 commented 1 year ago

We are getting the same thing.

AgentEnder commented 1 year ago

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

aikrez commented 12 months ago

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 commented 12 months ago

image

jaibeales commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

@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 commented 11 months ago

@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:

meeroslav commented 11 months ago

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

aikrez commented 11 months ago

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 commented 11 months ago

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!

HerrBertling commented 11 months ago

@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?

github-actions[bot] commented 10 months 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.