cached project graph cause hash failure when adding missing npm dependency
See original GitHub issueCurrent Behavior
Had a workspace with import '@testing-library/dom';
but this was not present as a dependency in package.json
it was however indirectly available as a derived dependency from @testing-library/angular
Now adding the missing dependency to package.json
caused hash calculation to fail here in hasher.js
:
hashProjectNodeSource(projectName) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!this.sourceHashes[projectName]) {
this.sourceHashes[projectName] = new Promise((res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b;
const p = this.projectGraph.nodes[projectName];
if (project_graph_1.isNpmProject(p)) {
res(this.hashing.hashArray([p.data.version]));
return;
}
for projectName === '@testing-library/dom'
when running e.g. nx test xxxx
because p === undefined
as this.projectGraph.nodes['@testing-library/dom']
was never set in the cache because '@testing-library/dom'
was not a dependency in package.json
If doing NX_CACHE_PROJECT_GRAPH=false nx test xxxx
the problem goes away
Expected Behavior
The nx test xxx
should complete without crash
suggested solution:
hashProjectNodeSource(projectName) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!this.sourceHashes[projectName]) {
this.sourceHashes[projectName] = new Promise((res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b;
const p = this.projectGraph.nodes[projectName];
////// <<<<<
if (!p) {
res(`__${projectName}__`);
return;
}
////// >>>>>
if (project_graph_1.isNpmProject(p)) {
res(this.hashing.hashArray([p.data.version]));
return;
}
Steps to Reproduce
Failure Logs
% nx test cue-web
(node:24420) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'type' of undefined
at Object.isNpmProject (/Users/jha/git/wt/CCIEFL-21273-corrupt-nx-cache/node_modules/@nrwl/workspace/src/core/project-graph/operators.js:52:20)
at ProjectHasher.<anonymous> (/Users/jha/git/wt/CCIEFL-21273-corrupt-nx-cache/node_modules/@nrwl/workspace/src/core/hasher/hasher.js:248:41)
at Generator.next (<anonymous>)
at /Users/jha/git/wt/CCIEFL-21273-corrupt-nx-cache/node_modules/tslib/tslib.js:117:75
at new Promise (<anonymous>)
at Object.__awaiter (/Users/jha/git/wt/CCIEFL-21273-corrupt-nx-cache/node_modules/tslib/tslib.js:113:16)
at /Users/jha/git/wt/CCIEFL-21273-corrupt-nx-cache/node_modules/@nrwl/workspace/src/core/hasher/hasher.js:241:79
at new Promise (<anonymous>)
at ProjectHasher.<anonymous> (/Users/jha/git/wt/CCIEFL-21273-corrupt-nx-cache/node_modules/@nrwl/workspace/src/core/hasher/hasher.js:241:50)
at Generator.next (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:24420) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:24420) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Environment
Node : 14.16.0 OS : darwin x64 npm : 6.14.11
nx : 12.9.0 @nrwl/angular : 12.9.0 @nrwl/cli : 12.9.0 @nrwl/cypress : 12.9.0 @nrwl/devkit : 12.9.0 @nrwl/eslint-plugin-nx : 12.9.0 @nrwl/express : Not Found @nrwl/jest : 12.9.0 @nrwl/linter : 12.9.0 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/nx-cloud : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 12.9.0 @nrwl/web : Not Found @nrwl/workspace : 12.9.0 @nrwl/storybook : 12.9.0 @nrwl/gatsby : Not Found typescript : 4.2.4
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11 (7 by maintainers)
Happened to me as well - I just called
nx clear-cache
and it fixed it.So did I 😊 But nx clear-cache is not an option when the problem occurs in the CI-CD pipeline 😒