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.

Workspace file utils throws: Cannot read property 'length' of undefined

See original GitHub issue

Current Behavior

When running nx run mytarget:build --verbose it fails with

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at Object.filesChanged (/.../node_modules/@nrwl/node/node_modules/@nrwl/workspace/src/core/file-utils.js:255:24)
    at Object.createProjectGraph (/.../node_modules/@nrwl/node/node_modules/@nrwl/workspace/src/core/project-graph/project-graph.js:21:32)
    at buildExecutor (/.../node_modules/@nrwl/node/src/executors/build/build.impl.js:28:39)
    at /.../node_modules/@nrwl/tao/src/commands/run.js:134:23
    at Generator.next (<anonymous>)
    at /.../node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)

Expected Behavior

It builds the target

Steps to Reproduce

Hard to tell issue is located inside

node_modules/@nrwl/node/node_modules/@nrwl/workspace/src/core/file-utils.js

function filesChanged(a, b) {
+  console.log(a,b)
+   if (a.length !== b?.length)
-   if (a.length !== b.length)
        return true;

The optional chaining on b does the trick and the console.log prints the following output:

[
  {
    file: 'package.json',
    hash: '1d085cde9f328c6fbe905dff7068ca8b70efdba0',
    ext: '.json'
  },
  {
    file: 'workspace.json',
    hash: '62266cc6a1d39f52da09833b25d8c6d545e46b19',
    ext: '.json'
  },
  {
    file: 'nx.json',
    hash: 'dcad049f2fa8f67840dc27514732a8992aae73aa',
    ext: '.json'
  },
  {
    file: 'tsconfig.base.json',
    hash: '11253ac5c2b7bc7ccc8003036c9379134582575c',
    ext: '.json'
  }
] undefined

Failure Logs

Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at Object.filesChanged (/.../node_modules/@nrwl/node/node_modules/@nrwl/workspace/src/core/file-utils.js:255:24)
    at Object.createProjectGraph (/.../node_modules/@nrwl/node/node_modules/@nrwl/workspace/src/core/project-graph/project-graph.js:21:32)
    at buildExecutor (/.../node_modules/@nrwl/node/src/executors/build/build.impl.js:28:39)
    at /.../node_modules/@nrwl/tao/src/commands/run.js:134:23
    at Generator.next (<anonymous>)
    at /.../node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)

Environment

 nx report

>  NX  Report complete - copy this into the issue template

  Node : 16.7.0
  OS   : darwin x64
  npm  : 7.20.3

  nx : 12.10.0
  @nrwl/angular : Not Found
  @nrwl/cli : 12.10.0
  @nrwl/cypress : 12.10.0
  @nrwl/devkit : 12.10.0
  @nrwl/eslint-plugin-nx : 12.10.0
  @nrwl/express : Not Found
  @nrwl/jest : 12.10.0
  @nrwl/linter : 12.10.0
  @nrwl/nest : 12.5.9
  @nrwl/next : Not Found
  @nrwl/node : 12.5.9
  @nrwl/nx-cloud : 12.3.13
  @nrwl/react : 12.10.0
  @nrwl/schematics : Not Found
  @nrwl/tao : 12.10.0
  @nrwl/web : 12.10.0
  @nrwl/workspace : 12.10.0
  @nrwl/storybook : 12.10.0
  @nrwl/gatsby : Not Found
  typescript : 4.4.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
eromanocommented, Mar 11, 2022

rm -rf ./node_modules/.cache/nx

2reactions
edbzncommented, Oct 20, 2021

Also ran into this issue, here is the report:

Node : 14.16.0
  OS   : linux x64
  yarn : 1.22.5
  
  nx : Not Found
  @nrwl/angular : 11.4.0
  @nrwl/cli : 11.4.0
  @nrwl/cypress : 11.4.0
  @nrwl/devkit : 11.4.0
  @nrwl/eslint-plugin-nx : 11.4.0
  @nrwl/express : Not Found
  @nrwl/jest : 11.4.0
  @nrwl/linter : 11.4.0
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : 11.4.0
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 11.4.0
  @nrwl/web : Not Found
  @nrwl/workspace : 11.4.0
  typescript : 4.1.5

I had to kill the node_modules and re-install the dependencies to get rid of this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property Length of Undefined in JavaScript
The JavaScript TypeError: Cannot read property 'length' of undefined occurs when the length property is read on an undefined variable.
Read more >
Typescript throws: Cannot read property 'length' of undefined
Good thing to check. I refactored some components manually and forgot to make updates inside the component.ts file to match. The error isn't ......
Read more >
Refreshing sidebar: Cannot read property 'length' of undefined
Summary Open "ISSUES AND MERGE REQUESTS" Clicking on "GitLab: Refresh sidebar" causes error messages: Failed to parse...
Read more >
Cannot read properties of undefined (reading 'length') - TrackJS
This message indicates that our code expects to have an object with a length property, but that object was not present.
Read more >
TypeError: Cannot read property 'length' of undefined
TypeError : Cannot read property 'length' of undefined. What's wrong with my code? Thanks. *. var carlos = [9.6,10.6,11.2,10.3,11.5]; var ...
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