nx-console icon indicating copy to clipboard operation
nx-console copied to clipboard

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

Open ThePlenkov opened this issue 1 year ago • 21 comments

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!

ThePlenkov avatar Apr 15 '24 08:04 ThePlenkov

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

  • could you provide a minimal repro of an instance where this issue happens?
  • what's your nx report results and vscode & nx console version?
  • please provide the logs from Output => Nx Language Server so I can see what's going on

MaxKless avatar Apr 15 '24 09:04 MaxKless

@MaxKless just did, thanks

ThePlenkov avatar Apr 15 '24 09:04 ThePlenkov

It would be great if you could provide some logs.

  • could you provide a minimal repro of an instance where this issue happens?
  • what's your vscode & nx console version?
  • please provide the logs from Output => Nx Language Server so I can see what's going on

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?

MaxKless avatar Apr 15 '24 10:04 MaxKless

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 avatar Apr 15 '24 11:04 ThePlenkov

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

ThePlenkov avatar Apr 15 '24 11:04 ThePlenkov

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

MaxKless avatar Apr 15 '24 11:04 MaxKless

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)

ThePlenkov avatar Apr 15 '24 11:04 ThePlenkov

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

MaxKless avatar Apr 15 '24 11:04 MaxKless

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

ThePlenkov avatar Apr 15 '24 12:04 ThePlenkov

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.

MaxKless avatar Apr 15 '24 13:04 MaxKless

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/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]_typ_ilc6bha6x27zkxd3csesxxyivu/node_modules/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js:61:21)

igortas avatar Apr 19 '24 19:04 igortas

Did you try to reload window?

ThePlenkov avatar Apr 19 '24 20:04 ThePlenkov

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...

igortas avatar Apr 19 '24 20:04 igortas

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

MaxKless avatar Apr 22 '24 08:04 MaxKless

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

  • I manually delete a page folder from the explorer
  • copy paste and existing page and rename it

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

sven-tred avatar Apr 30 '24 12:04 sven-tred

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

MaxKless avatar Apr 30 '24 12:04 MaxKless

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

sven-tred avatar Apr 30 '24 13:04 sven-tred

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

kurt-west avatar May 01 '24 07:05 kurt-west

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.

MaxKless avatar May 02 '24 09:05 MaxKless

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.

kurt-west avatar May 02 '24 12:05 kurt-west

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

MaxKless avatar May 02 '24 13:05 MaxKless

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

Jagan-P avatar Jun 18 '24 22:06 Jagan-P

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!

MaxKless avatar Jul 12 '24 12:07 MaxKless

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. :(

BleedingDev avatar Aug 27 '24 23:08 BleedingDev

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 avatar Aug 28 '24 10:08 ThePlenkov

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

ThePlenkov avatar Aug 28 '24 16:08 ThePlenkov

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

valentinoPereira avatar Sep 02 '24 14:09 valentinoPereira

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

MaxKless avatar Sep 02 '24 14:09 MaxKless