nx: ERROR: No cached ProjectGraph is available.

Current Behavior

Random nx crash in our Github CI during a build

Expected Behavior

nx can build our projects without failing

Steps to Reproduce

I guess new messages at the end of #10730 are kinda similar. Looks related to the latest release.

Failure Logs

> nx run generic-dynamodb-orm:build 
Error reading '/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.cache/nx/nxdeps.json'. Continue the process without the cache.
Error: ValueExpected in /home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.cache/nx/nxdeps.json at position 0
    at parseJson (/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/nx@14.4.3_@swc+core@1.2.215/node_modules/nx/src/utils/json.js:23:15)
    at readJsonFile (/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/nx@14.4.3_@swc+core@1.2.215/node_modules/nx/src/utils/fileutils.js:23:37)
    at readCache (/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/nx@14.4.3_@swc+core@1.2.215/node_modules/nx/src/project-graph/nx-deps-cache.js:41:49)
    at readCachedProjectGraph (/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/nx@14.4.3_@swc+core@1.2.215/node_modules/nx/src/project-graph/project-graph.js:20:61)
    at checkDependencies (/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/@nrwl+js@14.4.3_2ufozsgst4bthv2r67rno347d4/node_modules/@nrwl/js/src/utils/check-dependencies.js:7:62)
    at tscExecutor_1 (/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/@nrwl+js@14.4.3_2ufozsgst4bthv2r67rno347d4/node_modules/@nrwl/js/src/executors/tsc/tsc.impl.js:29:111)
    at tscExecutor_1.next (<anonymous>)
    at resume (/home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/tslib.js:230:48)
    at /home/ubuntu/actions-runner/_work/monorepo/monorepo/node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/tslib.js:229:[125](https://github.com/hublo/monorepo/runs/7410177714?check_suite_focus=true#step:11:126)
    at new Promise (<anonymous>)
 >  NX   [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.
   If you are leveraging \`readCachedProjectGraph()\` directly then you will need to refactor your usage to first ensure that
   the ProjectGraph is created by calling \`await createProjectGraphAsync()\` somewhere before attempting to read the data.
   If you encounter this error as part of running standard \`nx\` commands then please open an issue on https://github.com/nrwl/nx
   Pass --verbose to see the stacktrace.

Environment

❯ pnx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : darwin arm64
   pnpm : 7.5.0

   nx : 14.4.3
   @nrwl/angular : Not Found
   @nrwl/cypress : 14.4.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.4.3
   @nrwl/eslint-plugin-nx : 14.4.3
   @nrwl/express : Not Found
   @nrwl/jest : 14.4.3
   @nrwl/js : 14.4.3
   @nrwl/linter : 14.4.3
   @nrwl/nest : 14.4.3
   @nrwl/next : 14.4.2
   @nrwl/node : 14.4.3
   @nrwl/nx-cloud : 14.2.0
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 14.4.3
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.4.3
   @nrwl/web : 14.4.3
   @nrwl/workspace : 14.4.3
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 30 (7 by maintainers)

Most upvoted comments

@AgentEnder on our CI while Jest Tests run, we got this error. I think we cannot close this ticket because sometimes it shows up. Do you need more information from me? We are struggling with it for several months

Here’s an error

`Error reading ‘/home/ubuntu/workspace/PPM/REVIEW/FRONTEND_TESTS/ui/node_modules/.cache/nx/nxdeps.json’. Continue the process without the cache.

[2022-09-02T13:34:53.235Z] Error: UnexpectedEndOfString in /home/ubuntu/workspace/PPM/REVIEW/FRONTEND_TESTS/ui/node_modules/.cache/nx/nxdeps.json at position 4939768

[2022-09-02T13:34:53.235Z] at parseJson (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/src/utils/json.js:23:15)

[2022-09-02T13:34:53.235Z] at readJsonFile (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/src/utils/fileutils.js:23:37)

[2022-09-02T13:34:53.235Z] at readCache (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/src/project-graph/nx-deps-cache.js:41:49)

[2022-09-02T13:34:53.235Z] at readCachedProjectGraph (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/src/project-graph/project-graph.js:20:61)

[2022-09-02T13:34:53.235Z] at run (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/src/command-line/run.js:168:69)

[2022-09-02T13:34:53.235Z] at requireCli (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/bin/run-executor.js:20:23)

[2022-09-02T13:34:53.235Z] at Object.<anonymous> (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/bin/run-executor.js:14:1)

[2022-09-02T13:34:53.235Z] at Module._compile (node:internal/modules/cjs/loader:1105:14)

[2022-09-02T13:34:53.235Z] at Object.Module._extensions…js (node:internal/modules/cjs/loader:1159:10)

[2022-09-02T13:34:53.235Z] at Module.load (node:internal/modules/cjs/loader:981:32)

[2022-09-02T13:34:53.235Z] Could not find ‘nx’ module in this workspace. Error: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.

[2022-09-02T13:34:53.235Z]

[2022-09-02T13:34:53.235Z] If you are leveraging `readCachedProjectGraph()` directly then you will need to refactor your usage to first ensure that

[2022-09-02T13:34:53.235Z] the ProjectGraph is created by calling `await createProjectGraphAsync()` somewhere before attempting to read the data.

[2022-09-02T13:34:53.235Z]

[2022-09-02T13:34:53.235Z] If you encounter this error as part of running standard `nx` commands then please open an issue on https://github.com/nrwl/nx

[2022-09-02T13:34:53.235Z] at readCachedProjectGraph (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/src/project-graph/project-graph.js:29:15)

[2022-09-02T13:34:53.235Z] at run (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/src/command-line/run.js:168:69)

[2022-09-02T13:34:53.235Z] at requireCli (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/bin/run-executor.js:20:23)

[2022-09-02T13:34:53.235Z] at Object.<anonymous> (/home/ubuntu/jenkins-slave/caches/frontend/node_modules/nx/bin/run-executor.js:14:1)

[2022-09-02T13:34:53.235Z] at Module._compile (node:internal/modules/cjs/loader:1105:14)

[2022-09-02T13:34:53.235Z] at Object.Module._extensions…js (node:internal/modules/cjs/loader:1159:10)

[2022-09-02T13:34:53.235Z] at Module.load (node:internal/modules/cjs/loader:981:32)

[2022-09-02T13:34:53.235Z] at Function.Module._load (node:internal/modules/cjs/loader:822:12)

[2022-09-02T13:34:53.235Z] at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

[2022-09-02T13:34:53.235Z] at node:internal/main/run_main_module:17:47`

Same here, CI and local instances crash with the error message

Error reading ‘<redacted>/node_modules/.cache/nx/nxdeps.json’. Continue the process without the cache

npx nx report                                             

 >  NX   Report complete - copy this into the issue template

   Node : 14.19.3
   OS   : linux x64
   npm  : 6.14.17
   
   nx : 14.5.4
   @nrwl/angular : 14.5.4
   @nrwl/cypress : 14.5.4
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.5.4
   @nrwl/eslint-plugin-nx : 14.5.4
   @nrwl/express : Not Found
   @nrwl/jest : 14.5.4
   @nrwl/js : 14.5.4
   @nrwl/linter : 14.5.4
   @nrwl/nest : 14.5.4
   @nrwl/next : Not Found
   @nrwl/node : 14.5.4
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.5.4
   @nrwl/web : 14.5.4
   @nrwl/workspace : 14.5.4
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:
   	 @ngrx/component-store: 14.0.2
   	 @ngrx/effects: 14.0.2
   	 @ngrx/entity: 14.0.2
   	 @ngrx/router-store: 14.0.2
   	 @ngrx/store: 14.0.2
   	 @ngrx/schematics: 14.0.2
   	 @ngrx/store-devtools: 14.0.2

@B1Z1 I don’t think 14.5.8 contains the fix… also in my case the error reading nxdeps.json seems intermittent

Just updated nx to newest version (14.5.6) with nx migrate and got on CI same problem. This is first time, when CI blow up with this type of error. Any progress here? We want to use Angular 14.1 in application