Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running affected: Cannot read properties of undefined (reading 'name') #13802

Closed
newmankyle opened this issue Dec 13, 2022 · 2 comments
Assignees
Labels

Comments

@newmankyle
Copy link

Current Behavior

This error occurred after running the Cypress component-test generator.

My symptoms are identical to @jericopingul in issue #13668 , namely, I get this error when running any affected task

yarn stylelint:affected --base=origin/main --verbose
nx.js affected

Run target for affected projects

Run command using --base=[SHA1] (affected by the committed, uncommitted and untracked changes):
      --base  Base of the current branch (usually main)                                                                                    [string]
or using --base=[SHA1] --head=[SHA2] (affected by the committed changes):
      --base  Base of the current branch (usually main)                                                                                    [string]      --head  Latest commit of the current branch (usually HEAD)                                                                           [string]
or using:
      --files        Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas  
                                                                                                                                            [array]      --uncommitted  Uncommitted changes                                                                                                  [boolean]      --untracked    Untracked changes                                                                                                    [boolean]
Options:
      --help              Show help                                                                                                       [boolean]      --version           Show version number                                                                                             [boolean]      --target            Task to run for affected projects                                                                     [string] [required]      --output-style      Defines how Nx emits outputs tasks logs      [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes"]      --exclude           Exclude certain projects from being processed                                                       [array] [default: []]      --parallel          Max number of parallel processes [default is 3]                                                                  [string]      --runner            This is the name of the tasks runner configured in nx.json                                                       [string]  -c, --configuration     This is the configuration to use when performing tasks on projects                                               [string]      --verbose           Prints additional information about the commands (e.g., stack traces)                          [boolean] [default: false]      --nx-bail           Stop command execution after the first failed task                                             [boolean] [default: false]      --nx-ignore-cycles  Ignore cycles in the task graph                                                                [boolean] [default: false]      --skip-nx-cache     Rerun the tasks even when the results are available in the cache                               [boolean] [default: false]      --all               All projects                                                                                                    [boolean]
Examples:
  affected --target=custom-target                         Run custom target for all affected projects
  affected --target=test --parallel=5                     Run tests in parallel
  affected --target=test --all                            Run the test target for all projects
  affected --target=test --files=libs/mylib/src/index.ts  Run tests for all the projects affected by changing the index.ts file
  affected --target=test --base=main --head=HEAD          Run tests for all the projects affected by the changes between main and HEAD (e.g., PR)  
  affected --target=test --base=main~1 --head=main        Run tests for all the projects affected by the last commit on main

Find more information and examples at https://nx.dev/nx/affected

TypeError: Cannot read properties of undefined (reading 'name')
    at getTouchedNpmPackages (~\workspace\repo\node_modules\nx\src\project-graph\affected\locators\npm-packages.js:26:41)    at C:\Users\kdnewma\workspace\repo\node_modules\nx\src\project-graph\affected\affected-project-graph.js:31:27
    at Array.reduce (<anonymous>)
    at filterAffected (~\workspace\repo\node_modules\nx\src\project-graph\affected\affected-project-graph.js:30:52)      
    at projectsToRun (~\workspace\repo\node_modules\nx\src\command-line\affected.js:100:55)
    at Object.<anonymous> (~\workspace\repo\node_modules\nx\src\command-line\affected.js:29:26)
    at Generator.next (<anonymous>)
    at fulfilled (~\workspace\repo\node_modules\tslib\tslib.js:115:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Expected Behavior

No error

Github Repo

No response

Steps to Reproduce

If I disable the cache and daemon

NX_DAEMON=false NX_CACHE_PROJECT_GRAPH=false yarn stylelint:affected --base=origin/main

and step through the debugger, I can see that html-webpack-plugin isn't getting found by the mapper. This is because it is in an unusual format in the lockfile. This results in a lockfile dep with the format

"html-webpack-plugin-4@npm:html-webpack-plugin@^4":
  version: 4.5.2
  resolution: "html-webpack-plugin@npm:4.5.2"
  dependencies:
...
"html-webpack-plugin-5@npm:html-webpack-plugin@^5, html-webpack-plugin@npm:^5.5.0":
  version: 5.5.0
  resolution: "html-webpack-plugin@npm:5.5.0"
  dependencies:

If we look at yarn.ts, we can see this dep gets parsed incorrectly. So when the mapper tries to find it later as 'html-webpack-plugin', it's 'not found'.

I believe the culprit for this is @cypress/webpack-dev-server. You can see they're using the same format for their html-webpack-plugin dependencies.

Nx Report

Node : 16.14.0
   OS   : win32 x64
   yarn : 3.3.0

   nx : 15.0.13
   @nrwl/angular : 15.0.13
   @nrwl/cypress : 15.0.13
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.0.13
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.0.13
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.0.13
   @nrwl/js : 15.0.13
   @nrwl/linter : 15.0.13
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 15.0.13
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : 15.0.13
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.0.13
   @nrwl/web : Not Found
   @nrwl/webpack : 15.0.13
   @nrwl/workspace : 15.0.13
   typescript : 4.8.4
   ---------------------------------------
   Community plugins:
         ng-zorro-antd: 14.2.1
         ngx-daterangepicker-material: 6.0.0
         @compodoc/compodoc: 1.1.19
         @jscutlery/semver: 2.27.1
         ngx-deploy-npm: 4.3.0
         nx-stylelint: 14.0.2

Failure Logs

No response

Additional Information

These symptoms appeared after running the Cypress component-testing generator. The dependencies that were added:

  • "@cypress/webpack-dev-server": "^2.0.0"
  • "cypress": "^10.7.0
  • "html-webpack-plugin": "^5.5.0"
@AgentEnder AgentEnder added the scope: core core nx functionality label Dec 13, 2022
@meeroslav
Copy link
Contributor

This is solved with #13728

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants