question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cached project graph cause hash failure when adding missing npm dependency

See original GitHub issue

Current 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
logan-jobzmallcommented, Oct 7, 2021

Happened to me as well - I just called nx clear-cache and it fixed it.

1reaction
jonhammcommented, Oct 7, 2021

So did I 😊 But nx clear-cache is not an option when the problem occurs in the CI-CD pipeline 😒

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't install any package with node npm - Stack Overflow
I had this issue, and doing npm cache clean solved it.
Read more >
node2nix - npm
To fix this problem, npm install must be executed again so that the missing or changed dependencies are updated in the lock file....
Read more >
Troubleshooting CI/CD - GitLab Docs
A common reason a job is added to a pipeline unexpectedly is because the changes keyword always evaluates to true in certain cases....
Read more >
Changelog - Cypress Documentation
Fixed a regression introduced in the Electron browser in Cypress 10.8.0 where the CYPRESS_EVERY_NTH_FRAME environment variable was not being set appropriately ...
Read more >
Nx 14.4 — Inputs, optional npm scope, project graph cache ...
Our last release blog post has been published not even a month ago and we already released 2 more minors. You missed the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found