nx: Build failed with Node 21.3.0, Error: readCachedProjectGraph failed
Current Behavior
I can build my project on my local machine with fresh install,
but when I commit it to my repo and trigger the CI build,
it fails every time with the same error message:
Could not find 'nx' module in this workspace. Error: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.
Full log:
Dec 2 05:30:43 PM ==> Checking out commit 3214074ee8b495843bcfac1c9e5e487510b42cd7 in branch fix-ci
Dec 2 05:30:47 PM ==> Requesting node version >=21.x
Dec 2 05:30:47 PM (node:36) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
Dec 2 05:30:47 PM (Use `node --trace-warnings ...` to show where the warning was created)
Dec 2 05:30:47 PM ==> Using Node version 21.3.0 via /opt/render/project/src/package.json
Dec 2 05:30:47 PM ==> Docs on specifying a Node version: https://render.com/docs/node-version
Dec 2 05:30:53 PM ==> Running build command 'npm ci && node render-build.mjs'...
Dec 2 05:30:57 PM (node:63) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
Dec 2 05:30:57 PM (Use `node --trace-warnings ...` to show where the warning was created)
Dec 2 05:32:08 PM
Dec 2 05:32:08 PM added 2368 packages, and audited 2369 packages in 1m
Dec 2 05:32:08 PM
Dec 2 05:32:08 PM 350 packages are looking for funding
Dec 2 05:32:08 PM run `npm fund` for details
Dec 2 05:32:08 PM
Dec 2 05:32:08 PM 11 moderate severity vulnerabilities
Dec 2 05:32:08 PM
Dec 2 05:32:08 PM To address all issues (including breaking changes), run:
Dec 2 05:32:08 PM npm audit fix --force
Dec 2 05:32:08 PM
Dec 2 05:32:08 PM Run `npm audit` for details.
Dec 2 05:32:09 PM
Dec 2 05:32:09 PM > NX Resetting the Nx workspace cache and stopping the Nx Daemon.
Dec 2 05:32:09 PM
Dec 2 05:32:09 PM This might take a few minutes.
Dec 2 05:32:09 PM
Dec 2 05:32:09 PM
Dec 2 05:32:09 PM > NX Daemon Server - Stopped
Dec 2 05:32:09 PM
Dec 2 05:32:09 PM
Dec 2 05:32:09 PM > NX Successfully reset the Nx workspace.
Dec 2 05:32:09 PM
Dec 2 05:32:12 PM
Dec 2 05:32:12 PM > NX Report complete - copy this into the issue template
Dec 2 05:32:12 PM
Dec 2 05:32:12 PM Node : 21.3.0
Dec 2 05:32:12 PM OS : linux-x64
Dec 2 05:32:12 PM npm : 10.2.4
Dec 2 05:32:12 PM
Dec 2 05:32:12 PM nx : 17.1.3
Dec 2 05:32:12 PM @nx/js : 17.1.3
Dec 2 05:32:12 PM @nx/linter : 17.1.3
Dec 2 05:32:12 PM @nx/eslint : 17.1.3
Dec 2 05:32:12 PM @nx/workspace : 17.1.3
Dec 2 05:32:12 PM @nx/cypress : 17.1.3
Dec 2 05:32:12 PM @nx/devkit : 17.1.3
Dec 2 05:32:12 PM @nx/eslint-plugin : 17.1.3
Dec 2 05:32:12 PM @nx/react : 17.1.3
Dec 2 05:32:12 PM @nx/storybook : 17.1.3
Dec 2 05:32:12 PM @nrwl/tao : 17.1.3
Dec 2 05:32:12 PM @nx/vite : 17.1.3
Dec 2 05:32:12 PM @nx/web : 17.1.3
Dec 2 05:32:12 PM typescript : 4.9.5
Dec 2 05:32:12 PM
Dec 2 05:32:14 PM [NX CLOUD] Verifying current cloud bundle
Dec 2 05:32:14 PM (node:595) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
Dec 2 05:32:14 PM (Use `node --trace-warnings ...` to show where the warning was created)
Dec 2 05:32:14 PM [NX CLOUD] Currently installed bundle is invalid, downloading version 2312.01.6 from https://cloud.nx.app/nx-cloud/static/client-bundle
Dec 2 05:32:15 PM [NX CLOUD] Done: /opt/render/project/src/.nx/cache/cloud/2312.01.6
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM > NX Running target build for project web and 1 task it depends on:
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM [Nx Cloud] Did not identify a VCS platform.
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM > NX RunStart
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM {
Dec 2 05:32:15 PM "meta": {},
Dec 2 05:32:15 PM "branch": null,
Dec 2 05:32:15 PM "runGroup": "3214074ee8b495843bcfac1c9e5e487510b42cd7",
Dec 2 05:32:15 PM "ciExecutionId": null,
Dec 2 05:32:15 PM "ciExecutionEnv": "",
Dec 2 05:32:15 PM "hashes": [
Dec 2 05:32:15 PM "13318270150725750156",
Dec 2 05:32:15 PM "16697682022918137113"
Dec 2 05:32:15 PM ],
Dec 2 05:32:15 PM "machineInfo": {
Dec 2 05:32:15 PM "machineId": "ubRguwX2ERTAK3dlextrOA==",
Dec 2 05:32:15 PM "platform": "linux",
Dec 2 05:32:15 PM "version": "#16~22.04.1-Ubuntu SMP Sun Nov 5 20:08:16 UTC 2023",
Dec 2 05:32:15 PM "cpuCores": 16
Dec 2 05:32:15 PM },
Dec 2 05:32:15 PM "vcsContext": null
Dec 2 05:32:15 PM }
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM > NX Nx Cloud: Cache miss 16697682022918137113.
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM > nx run shared-ui:build:production
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM Could not find 'nx' module in this workspace. Error: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM If you are leveraging \`readCachedProjectGraph()\` directly then you will need to refactor your usage to first ensure that
Dec 2 05:32:15 PM the ProjectGraph is created by calling \`await createProjectGraphAsync()\` somewhere before attempting to read the data.
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM If you encounter this error as part of running standard \`nx\` commands then please open an issue on https://github.com/nrwl/nx
Dec 2 05:32:15 PM at readCachedProjectGraph (/opt/render/project/src/node_modules/nx/src/project-graph/project-graph.js:30:15)
Dec 2 05:32:15 PM at run (/opt/render/project/src/node_modules/nx/src/command-line/run/run.js:151:69)
Dec 2 05:32:15 PM at process.<anonymous> (/opt/render/project/src/node_modules/nx/bin/run-executor.js:59:48)
Dec 2 05:32:15 PM at process.emit (node:events:519:28)
Dec 2 05:32:15 PM at emit (node:internal/child_process:951:14)
Dec 2 05:32:15 PM at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM > NX Running target build for project web and 1 task it depends on failed
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM Failed tasks:
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM - shared-ui:build:production
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM Hint: run the command with --verbose for more details.
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM > NX Nx Cloud Problems
Dec 2 05:32:15 PM
Dec 2 05:32:15 PM - Error when connecting to Nx Cloud. Code: 401. Error: This workspace is more than a week old and is unclaimed. Workspaces must be claimed within 7 days of creation. Claim your workspace at https://cloud.nx.app/orgs/workspace-setup?accessToken=
Dec 2 05:32:15 PM
Dec 2 05:32:17 PM [NX CLOUD] Verifying current cloud bundle
Dec 2 05:32:17 PM [NX CLOUD] A local bundle currently exists: {
Dec 2 05:32:17 PM version: '2312.01.6',
Dec 2 05:32:17 PM fullPath: '/opt/render/project/src/.nx/cache/cloud/2312.01.6'
Dec 2 05:32:17 PM }
Dec 2 05:32:17 PM [NX CLOUD] Last verification was within the past 30 minutes, will not verify this time
Dec 2 05:32:17 PM [NX CLOUD] Done: /opt/render/project/src/.nx/cache/cloud/2312.01.6
Dec 2 05:32:17 PM [Nx Cloud] Did not identify a VCS platform.
Dec 2 05:32:17 PM
Dec 2 05:32:17 PM > NX RunStart
Dec 2 05:32:17 PM
Dec 2 05:32:17 PM
Dec 2 05:32:17 PM {
Dec 2 05:32:17 PM "meta": {},
Dec 2 05:32:17 PM "branch": null,
Dec 2 05:32:17 PM "runGroup": "3214074ee8b495843bcfac1c9e5e487510b42cd7",
Dec 2 05:32:17 PM "ciExecutionId": null,
Dec 2 05:32:17 PM "ciExecutionEnv": "",
Dec 2 05:32:17 PM "hashes": [
Dec 2 05:32:17 PM "5935880398960322236"
Dec 2 05:32:17 PM ],
Dec 2 05:32:17 PM "machineInfo": {
Dec 2 05:32:17 PM "machineId": "ubRguwX2ERTAK3dlextrOA==",
Dec 2 05:32:17 PM "platform": "linux",
Dec 2 05:32:17 PM "version": "#16~22.04.1-Ubuntu SMP Sun Nov 5 20:08:16 UTC 2023",
Dec 2 05:32:17 PM "cpuCores": 16
Dec 2 05:32:17 PM },
Dec 2 05:32:17 PM "vcsContext": null
Dec 2 05:32:17 PM }
Dec 2 05:32:17 PM
Dec 2 05:32:17 PM (node:667) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
Dec 2 05:32:17 PM (Use `node --trace-warnings ...` to show where the warning was created)
Dec 2 05:32:17 PM
Dec 2 05:32:17 PM > NX Nx Cloud: Cache miss 5935880398960322236.
Dec 2 05:32:17 PM
Dec 2 05:32:17 PM
Dec 2 05:32:17 PM > nx run api:build:production
Dec 2 05:32:17 PM
Dec 2 05:32:18 PM Could not find 'nx' module in this workspace. Error: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM If you are leveraging \`readCachedProjectGraph()\` directly then you will need to refactor your usage to first ensure that
Dec 2 05:32:18 PM the ProjectGraph is created by calling \`await createProjectGraphAsync()\` somewhere before attempting to read the data.
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM If you encounter this error as part of running standard \`nx\` commands then please open an issue on https://github.com/nrwl/nx
Dec 2 05:32:18 PM at readCachedProjectGraph (/opt/render/project/src/node_modules/nx/src/project-graph/project-graph.js:30:15)
Dec 2 05:32:18 PM at run (/opt/render/project/src/node_modules/nx/src/command-line/run/run.js:151:69)
Dec 2 05:32:18 PM at process.<anonymous> (/opt/render/project/src/node_modules/nx/bin/run-executor.js:59:48)
Dec 2 05:32:18 PM at process.emit (node:events:519:28)
Dec 2 05:32:18 PM at emit (node:internal/child_process:951:14)
Dec 2 05:32:18 PM at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM > NX Running target build for project api failed
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM Failed tasks:
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM - api:build:production
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM Hint: run the command with --verbose for more details.
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM > NX Nx Cloud Problems
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM - Error when connecting to Nx Cloud. Code: 401. Error: This workspace is more than a week old and is unclaimed. Workspaces must be claimed within 7 days of creation. Claim your workspace at https://cloud.nx.app/orgs/workspace-setup?accessToken=
Dec 2 05:32:18 PM
Dec 2 05:32:18 PM ==> Uploading build...
Dec 2 05:32:39 PM ==> Build uploaded in 11s
Dec 2 05:32:39 PM ==> Build successful 🎉
Dec 2 05:32:41 PM ==> Deploying...
Dec 2 05:33:17 PM ==> Requesting node version >=21.x
Dec 2 05:33:17 PM (node:41) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
Dec 2 05:33:17 PM (Use `node --trace-warnings ...` to show where the warning was created)
Dec 2 05:33:18 PM ==> Using Node version 21.3.0 via /opt/render/project/src/package.json
Dec 2 05:33:18 PM ==> Docs on specifying a Node version: https://render.com/docs/node-version
Dec 2 05:33:18 PM ==> Running 'node dist/apps/api/main.js'
Dec 2 05:33:18 PM node:internal/modules/cjs/loader:1147
Dec 2 05:33:18 PM throw err;
Dec 2 05:33:18 PM ^
Dec 2 05:33:18 PM
Dec 2 05:33:18 PM Error: Cannot find module '/opt/render/project/src/dist/apps/api/main.js'
Dec 2 05:33:18 PM at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
Dec 2 05:33:18 PM at Module._load (node:internal/modules/cjs/loader:985:27)
Dec 2 05:33:18 PM at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
Dec 2 05:33:18 PM at node:internal/main/run_main_module:28:49 {
Dec 2 05:33:18 PM code: 'MODULE_NOT_FOUND',
Dec 2 05:33:18 PM requireStack: []
Dec 2 05:33:18 PM }
Dec 2 05:33:18 PM
Dec 2 05:33:18 PM Node.js v21.3.0
Dec 2 05:33:22 PM ==> Requesting node version >=21.x
Dec 2 05:33:22 PM ==> Using Node version 21.3.0 via /opt/render/project/src/package.json
Dec 2 05:33:22 PM ==> Docs on specifying a Node version: https://render.com/docs/node-version
Dec 2 05:33:22 PM ==> Running 'node dist/apps/api/main.js'
Dec 2 05:33:23 PM node:internal/modules/cjs/loader:1147
Dec 2 05:33:23 PM throw err;
Dec 2 05:33:23 PM ^
Dec 2 05:33:23 PM
Dec 2 05:33:23 PM Error: Cannot find module '/opt/render/project/src/dist/apps/api/main.js'
Dec 2 05:33:23 PM at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
Dec 2 05:33:23 PM at Module._load (node:internal/modules/cjs/loader:985:27)
Dec 2 05:33:23 PM at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
Dec 2 05:33:23 PM at node:internal/main/run_main_module:28:49 {
Dec 2 05:33:23 PM code: 'MODULE_NOT_FOUND',
Dec 2 05:33:23 PM requireStack: []
Dec 2 05:33:23 PM }
Dec 2 05:33:23 PM
Dec 2 05:33:23 PM Node.js v21.3.0
Expected Behavior
It should build the project successfully
GitHub Repo
No response
Steps to Reproduce
- Prepare the build script:
// build.mjs
import { spawn } from 'child_process';
function run(cmd) {
return new Promise((resolve) => {
const proc = spawn('sh', ['-c', cmd]);
proc.stdout.on('data', (data) => {
process.stdout.write(data);
});
proc.stderr.on('data', (data) => {
process.stderr.write(data);
});
proc.on('exit', (code) => {
resolve(code);
});
});
}
(async () => {
await run('rm -rf .nx');
await run('npx nx reset');
await run('nx report');
await run('npx nx build web --verbose');
})();
npm ci && node build.mjs
Nx Report
Dec 2 05:32:12 PM Node : 21.3.0
Dec 2 05:32:12 PM OS : linux-x64
Dec 2 05:32:12 PM npm : 10.2.4
Dec 2 05:32:12 PM
Dec 2 05:32:12 PM nx : 17.1.3
Dec 2 05:32:12 PM @nx/js : 17.1.3
Dec 2 05:32:12 PM @nx/linter : 17.1.3
Dec 2 05:32:12 PM @nx/eslint : 17.1.3
Dec 2 05:32:12 PM @nx/workspace : 17.1.3
Dec 2 05:32:12 PM @nx/cypress : 17.1.3
Dec 2 05:32:12 PM @nx/devkit : 17.1.3
Dec 2 05:32:12 PM @nx/eslint-plugin : 17.1.3
Dec 2 05:32:12 PM @nx/react : 17.1.3
Dec 2 05:32:12 PM @nx/storybook : 17.1.3
Dec 2 05:32:12 PM @nrwl/tao : 17.1.3
Dec 2 05:32:12 PM @nx/vite : 17.1.3
Dec 2 05:32:12 PM @nx/web : 17.1.3
Dec 2 05:32:12 PM typescript : 4.9.5
Failure Logs
No response
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 6
- Comments: 16 (7 by maintainers)
I suddenly also have this issue on one of my deloyments (of 3 servies I deploy with nx)
UPDATE: if I put the build on the same version as the local install (CI was building on node 21, and local was 20). then it all works again
The odd Node versions aren’t stable and Nx does not guarantee support for them. I would recommend not using any odd versions for production.
Also had this problem.
Upgrading Node to 21.4.0 has indeed helped and also resolved another issue I had when running nx migrate
Now I’m running in this issue https://github.com/nrwl/nx/issues/20675
So it seem the issue is caused by the Node 21.3.0 release, by explicitly setting the Node version to 21.2.0 in package.json
The build is working again in CI
Similar solution in my case: defining the exact node version in the Dockerfile.
Same issue here - CI with GitHub Actions, changing
node-versionin theactions/setup-nodestep to exactly match my local version stopped the CI runs from failing for me.Here’s the commit that fixed my issues, changing
21.xto21.1, matching my local install.I have the same issue, also hosted on Render. With my last commit ~12 hours ago everything worked as expected.
nx resetdidn’t helpCI: