nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.28k stars 2.32k forks source link

"Cannot read property 'tags' of undefined" in "nx run-many" eslint hasher after upgrading Nx 12.6.4->12.7.2 #6760

Closed Nick-Lucas closed 3 years ago

Nick-Lucas commented 3 years ago

We use commands like nx run-many --with-deps --target=lint --projects admin to test all code associated with a application in CI. This is useful because we have separate pipelines for each application and means we're linting/testing the minimum amount of code.

This was working on 12.6.4, but we ran nx migrate latest today which upgraded to 12.7.2 and the command is failing with the error

TypeError: Cannot read property 'tags' of undefined
    at /Users/user/dev/app/node_modules/@nrwl/linter/src/executors/eslint/hasher.js:17:75
    at Array.map (<anonymous>)
    at /Users/user/dev/app/node_modules/@nrwl/linter/src/executors/eslint/hasher.js:17:44
    at Generator.next (<anonymous>)
    at fulfilled (/Users/user/dev/app/node_modules/tslib/tslib.js:114:62)

The problem code is

// From @nrwl/linter/src/executors/eslint/hasher.js
const deps = allDeps(task.id, taskGraph);
const nxJson = fileutils_1.readJsonFile(path_1.join(app_root_1.appRootPath, 'nx.json'));
console.log("NX", nxJson, "DEPS", deps)
const tags = hasher.hashArray(deps.map((d) => (nxJson.projects[d]/* This is undefined */.tags || []).join('|')));

// Logged output:

NX {
  npmScope: 'app',
  affected: { defaultBase: 'dev/main' },
  implicitDependencies: {
    'package.json': { dependencies: '*', devDependencies: '*' },
    '.eslintrc.json': '*'
  },
  tasksRunnerOptions: {
    default: {
      runner: '@nrwl/workspace/tasks-runners/default',
      options: [Object]
    }
  },
  targetDependencies: { build: [ [Object] ] },
  projects: {
    admin: { tags: [] },
    'admin-e2e': { tags: [], implicitDependencies: [Array] },
    api: { tags: [] },
    'api-auth-node': { tags: [] },
    portal: { tags: [] },
    'portal-e2e': { tags: [], implicitDependencies: [Array] },
    'portal-e2e-legacy': { tags: [], implicitDependencies: [Array] },
    theme: { tags: [] }
  }
} 

DEPS [ [], [] ]

From the output it looks like some change under allDeps() has caused it not to return keys any longer

maxisam commented 2 years ago

@leosvelperez I still have the same issue with nx 12.9

Node : 14.17.1 OS : win32 x64 yarn : 1.22.5

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 : 12.3.12 @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 12.9.0 @nrwl/web : 12.9.0 @nrwl/workspace : 12.9.0 @nrwl/storybook : 12.9.0 @nrwl/gatsby : Not Found typescript : 4.3.5

nelsond6 commented 2 years ago

@leosvelperez - This is still an issue with workspaces that have the "per-project" configuration applied. I just tested this. When I have a standard workspace that has one app and one lib dependency without the per-project configuration, tags and linting work. But if I apply the command "nx g @nrwl/workspace:convert-to-nx-project --all" to the project, then I get the same error defined in this ticket -> TypeError: Cannot read property 'tags' of undefined

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.