nrwl / nx-console

Nx Console is the user interface for Nx & Lerna.
https://nx.dev
MIT License
1.31k stars 213 forks source link

Nx console extension always fails to build graph when changing the file tree #2091

Closed ThePlenkov closed 4 months ago

ThePlenkov commented 7 months ago

Hi! I have noticed that nx console extension permanently fails if file tree is changed.

Just for example - it's enough just to delete some JS file like jest.preset.js and it's already enough for the extension to stop working.

What is interesting - nx command line stays working normally.

WHat helps - is VS Code reloading, which is not really convenient.

Could you please check why it happens - it seems like the extension have some internal caching and it doesn't really catch file changes.

Node   : 20.12.0
OS     : linux-x64
npm    : 10.5.0

nx                 : 18.2.4
@nx/js             : 18.2.4
@nx/jest           : 18.2.4
@nx/linter         : 18.2.4
@nx/eslint         : 18.2.4
@nx/workspace      : 18.2.4
@nx/devkit         : 18.2.4
@nx/eslint-plugin  : 18.2.4
@nrwl/tao          : 18.2.4
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/jest/plugin

Thanks!

MaxKless commented 7 months ago

It would be great if you could provide some logs or any of the information we ask for when filing a bug.

ThePlenkov commented 7 months ago

@MaxKless just did, thanks

MaxKless commented 7 months ago

It would be great if you could provide some logs.

What do you mean by 'permanently fails'? What issues are you seeing? Is the project view not showing projects anymore? Is the graph/PDV view empty? Anything else?

ThePlenkov commented 7 months ago

Well I mean when this happens i have something like this: image

or like this: image

But point is - even after fixing - this error stays. So i spent an hour to understand why ( because nx command works ) and then I just found out that just reloading the window helps to fix it.

ThePlenkov commented 7 months ago

now I tried to reproduce the error with jest config and it doesn't happen, i will try to detect this situation again and will update with a log

MaxKless commented 7 months ago

Okay thanks, I've seen this issue before it's good to have another report. Could you provide some logs? You can find them under Output -> Nx Language Server

ThePlenkov commented 7 months ago

Sure, usually it's something like this:

The "nx/js/dependencies-and-lockfile" plugin threw an error while creating dependencies:
    Error: "Unable to load /workspaces/fs-observability-aws/stacks/mq/jest.config.ts: No such file or directory (os error 2)"
        at buildExplicitTypeScriptDependencies (/workspaces/fs-observability-aws/node_modules/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js:61:21)
        at buildExplicitDependencies (/workspaces/fs-observability-aws/node_modules/nx/src/plugins/js/project-graph/build-dependencies/build-dependencies.js:19:120)
        at Object.createDependencies (/workspaces/fs-observability-aws/node_modules/nx/src/plugins/js/index.js:70:92)
        at /workspaces/fs-observability-aws/node_modules/nx/src/project-graph/build-project-graph.js:202:47
        at Array.map (<anonymous>)
        at updateProjectGraphWithPlugins (/workspaces/fs-observability-aws/node_modules/nx/src/project-graph/build-project-graph.js:199:47)
        at async buildProjectGraphUsingContext (/workspaces/fs-observability-aws/node_modules/nx/src/project-graph/build-project-graph.js:104:24)
        at async buildProjectGraphUsingProjectFileMap (/workspaces/fs-observability-aws/node_modules/nx/src/project-graph/build-project-graph.js:68:24)
        at async buildProjectGraphAndSourceMapsWithoutDaemon (/workspaces/fs-observability-aws/node_modules/nx/src/project-graph/project-graph.js:100:30)
        at async Object.createProjectGraphAndSourceMapsAsync (/workspaces/fs-observability-aws/node_modules/nx/src/project-graph/project-graph.js:240:25)
MaxKless commented 7 months ago

Do you have more than just that snippet? I'm specifically looking for things that mention file watching. The full logs help me get a better image of where things go wrong

ThePlenkov commented 7 months ago

I think it's not even about the error. Like for example I just started a new project and added a new library, and it's still not shown in the extension ( even when I press refresh ) but is visible in cli: image

MaxKless commented 7 months ago

yes that sounds like an issue with file watching. Would you mind pasting your full logs from Output -> Nx Language Server when this happens? There's a bunch of information regarding file watching in there.

igortas commented 7 months ago

I've replaced vite.config.ts to vite.config.mts and now breaks all the time, even I revert back to ts

Failed to process project graph.
  The "nx/js/dependencies-and-lockfile" plugin threw an error while creating dependencies:
    Error: "Unable to load /home/igor/projects/myprojects/coffeeshop/apps/frontend/vite.config.mts.timestamp-1713555430444-84230d8eb717d.mjs: No such file or directory (os error 2)"
        at buildExplicitTypeScriptDependencies (/home/igor/projects/myprojects/coffeeshop/node_modules/.pnpm/nx@18.3.2_@swc-node+register@1.9.0_@swc+core@1.4.16_@swc+helpers@0.5.10__@swc+types@0.1.6_typ_ilc6bha6x27zkxd3csesxxyivu/node_modules/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js:61:21)
ThePlenkov commented 7 months ago

Did you try to reload window?

igortas commented 7 months ago

I'm removing the .nx cache manually, and it works, not works with reload... I'm getting also NX LOCK-FILES-CHANGED all the time, I will try to skip the cache...

MaxKless commented 7 months ago

I'm working on some changes to make Nx Console more resilient to changes like this :)

sven-tred commented 7 months ago

@MaxKless I have roughly the same issue. This can happen when

The copy paste error:

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Failed to process project graph.
  The "nx/js/dependencies-and-lockfile" plugin threw an error while creating dependencies:
    Error: "Unable to load /home/usr/Documents/repos/clients/apps/webapp/src/app/cards copy/page.tsx: No such file or directory (os error 2)"
        at buildExplicitTypeScriptDependencies (/home/usr/Documents/repos/clients/node_modules/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js:61:21)
        at buildExplicitDependencies (/home/usr/Documents/repos/clients/node_modules/nx/src/plugins/js/project-graph/build-dependencies/build-dependencies.js:19:120)
        at Object.createDependencies (/home/usr/Documents/repos/clients/node_modules/nx/src/plugins/js/index.js:70:92)
        at LoadedNxPlugin.createDependencies (/home/usr/Documents/repos/clients/node_modules/nx/src/project-graph/plugins/internal-api.js:27:59)
        at /home/usr/Documents/repos/clients/node_modules/nx/src/project-graph/build-project-graph.js:200:47
        at Array.map (<anonymous>)
        at updateProjectGraphWithPlugins (/home/usr/Documents/repos/clients/node_modules/nx/src/project-graph/build-project-graph.js:197:47)
        at buildProjectGraphUsingContext (/home/usr/Documents/repos/clients/node_modules/nx/src/project-graph/build-project-graph.js:103:30)
        at async buildProjectGraphUsingProjectFileMap (/home/usr/Documents/repos/clients/node_modules/nx/src/project-graph/build-project-graph.js:67:24)
        at async createAndSerializeProjectGraph (/home/usr/Documents/repos/clients/node_modules/nx/src/daemon/server/project-graph-incremental-recomputation.js:229:55)] {
  name: 'ProjectGraphError'
}

The Daemon is having a hard time keeping track of files. I'm on Ubuntu 22.04.4

MaxKless commented 7 months ago

can you try adding this to your .env NX_ISOLATE_PLUGINS=true

It should fix this error and will be default behaviour in the future. @ThePlenkov @igortas @sven-tred

sven-tred commented 7 months ago

can you try adding this to your .env NX_ISOLATE_PLUGINS=true

It should fix this error and will be default behaviour in the future. @ThePlenkov @igortas @sven-tred

That didn't quite do the trick @MaxKless :(

kurt-west commented 7 months ago

@MaxKless While refactoring - moving files, renaming, etc. - TS code, I get the same The "nx/js/dependencies-and-lockfile" plugin threw an error while creating dependencies: error as the others above.

The NX_ISOLATE_PLUGINS=true doesn't make a difference in my case.

yarn nx reset fixes the problem, as does manually deleting the project-graph.json file in .nx/cache

Looking at the daemon.log file it looks like the daemon crashes when trying to create the project graph and then when you run a command after it gets stuck with a bad project graph.

Node  : 20.11.0
OS    : win-x64
yarn  : 4.1.1
nx    : 18.2.4

Moved files with drag and drop in code; cut-paste results in the same error --------------------------------------
[NX Daemon Server] - 2024-05-01T05:37:42.830Z - [WATCHER]: 0 file(s) created or restored, 3 file(s) modified, 0 file(s) deleted
[NX Daemon Server] - 2024-05-01T05:37:43.237Z - [REQUEST]: Updated workspace context based on watched changes, recomputing project graph...
[NX Daemon Server] - 2024-05-01T05:37:43.237Z - [REQUEST]: libs/features/global-settings/src/role/api/index.ts,libs/features/global-settings/src/role/domain/index.ts,libs/features/global-settings/src/role/contracts/index.ts
[NX Daemon Server] - 2024-05-01T05:37:43.237Z - [REQUEST]: 
[NX Daemon Server] - 2024-05-01T05:37:43.293Z - Error detected when creating a project graph: Failed to create dependencies. See above for errors
[NX Daemon Server] - 2024-05-01T05:37:43.293Z - Time taken for 'hash changed files from watcher' 2.00760000012815ms

Tried to start the project with here -------------------------------------------------------------------------------
[NX Daemon Server] - 2024-05-01T05:37:47.130Z - Established a connection. Number of open connections: 1
[NX Daemon Server] - 2024-05-01T05:37:47.131Z - Closed a connection. Number of open connections: 0
[NX Daemon Server] - 2024-05-01T05:37:47.131Z - Established a connection. Number of open connections: 1
[NX Daemon Server] - 2024-05-01T05:37:47.132Z - [REQUEST]: Client Request for Project Graph Received
[NX Daemon Server] - 2024-05-01T05:37:47.132Z - [REQUEST]: Responding to the client with an error. Error when preparing serialized project graph. The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.
DaemonProjectGraphError: The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.
    at processFilesAndCreateAndSerializeProjectGraph (D:\nx-sandbox\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:182:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Timeout._onTimeout (D:\nx-sandbox\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:84:13)
MaxKless commented 7 months ago

thanks for checking it out. After setting the env variable, did you run nx reset & restart VSCode? Otherwise the bug still persists and I will look into it.

kurt-west commented 7 months ago

thanks for checking it out. After setting the env variable, did you run nx reset & restart VSCode? Otherwise the bug still persists and I will look into it.

The env is still set and verified to be active in the env, restarted code/computer multiple times, and nx reset at least 20 times due to it crashing.

MaxKless commented 7 months ago

That makes sense because the env var is handled only in later versions... my bad, forgot to check. If you can try updating to the latest nx 19 beta or be patient for just a few more days, the plugin isolation code should be available to you :)

Jagan-P commented 5 months ago

I'm removing the .nx cache manually, and it works, not works with reload... I'm getting also NX LOCK-FILES-CHANGED all the time, I will try to skip the cache...

I am seeing the same error

[Failed to process project graph.
  The "nx/js/dependencies-and-lockfile" plugin threw an error while creating dependencies:

Deleting the .nx folder in the project root solved it. Thanks

MaxKless commented 4 months ago

I think this is solved :) Either way, it has to do with Nx itself and not Nx Console, necessarily. Please let me know if you keep running into issues :) Thanks!

BleedingDev commented 3 months ago

Today I've run into this issue when trying to build docker image. Here is my Github Action output: https://github.com/NaucMeIT/web/actions/runs/10587556981/job/29338499413

Is there something more you need, @MaxKless? Current code is in the repository, I keep fighting with Prisma + Nx + Bun combo and this just another issue that popped up after I moved forward with Prisma issue. :(

ThePlenkov commented 3 months ago

I also have it now. Deletion of the workspace project breaks everything until I restart ide. With code spaces restart really takes time because it stoops container long.

ThePlenkov commented 3 months ago

@MaxKless the extension is very unstable now unfortuantely because of the plugins. I permanently have problem like plugin failed. CLI works, extension not. Have to refersh it very often.

valentinoPereira commented 3 months ago

@MaxKless While refactoring - moving files, renaming, etc. - TS code, I get the same The "nx/js/dependencies-and-lockfile" plugin threw an error while creating dependencies: error as the others above.

The NX_ISOLATE_PLUGINS=true doesn't make a difference in my case.

yarn nx reset fixes the problem, as does manually deleting the project-graph.json file in .nx/cache

Looking at the daemon.log file it looks like the daemon crashes when trying to create the project graph and then when you run a command after it gets stuck with a bad project graph.

Node  : 20.11.0
OS    : win-x64
yarn  : 4.1.1
nx    : 18.2.4

Moved files with drag and drop in code; cut-paste results in the same error --------------------------------------
[NX Daemon Server] - 2024-05-01T05:37:42.830Z - [WATCHER]: 0 file(s) created or restored, 3 file(s) modified, 0 file(s) deleted
[NX Daemon Server] - 2024-05-01T05:37:43.237Z - [REQUEST]: Updated workspace context based on watched changes, recomputing project graph...
[NX Daemon Server] - 2024-05-01T05:37:43.237Z - [REQUEST]: libs/features/global-settings/src/role/api/index.ts,libs/features/global-settings/src/role/domain/index.ts,libs/features/global-settings/src/role/contracts/index.ts
[NX Daemon Server] - 2024-05-01T05:37:43.237Z - [REQUEST]: 
[NX Daemon Server] - 2024-05-01T05:37:43.293Z - Error detected when creating a project graph: Failed to create dependencies. See above for errors
[NX Daemon Server] - 2024-05-01T05:37:43.293Z - Time taken for 'hash changed files from watcher' 2.00760000012815ms

Tried to start the project with here -------------------------------------------------------------------------------
[NX Daemon Server] - 2024-05-01T05:37:47.130Z - Established a connection. Number of open connections: 1
[NX Daemon Server] - 2024-05-01T05:37:47.131Z - Closed a connection. Number of open connections: 0
[NX Daemon Server] - 2024-05-01T05:37:47.131Z - Established a connection. Number of open connections: 1
[NX Daemon Server] - 2024-05-01T05:37:47.132Z - [REQUEST]: Client Request for Project Graph Received
[NX Daemon Server] - 2024-05-01T05:37:47.132Z - [REQUEST]: Responding to the client with an error. Error when preparing serialized project graph. The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.
DaemonProjectGraphError: The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.
    at processFilesAndCreateAndSerializeProjectGraph (D:\nx-sandbox\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:182:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Timeout._onTimeout (D:\nx-sandbox\node_modules\nx\src\daemon\server\project-graph-incremental-recomputation.js:84:13)

Thanks this solved my issue. I was getting "Failed to create dependencies." error, the other solutions didn't work.

MaxKless commented 3 months ago

Hey @ThePlenkov this is becoming really polluted on here. Sorry to hear you're having difficulties at the moment, I'd love to help out. Can you create a new issue with the errors you're seeing and an nx report? A repro would be awesome as well

sebastianrothbucher commented 3 weeks ago

Killing and restarting the background daemon did the trick for me