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

readTargetOptions devkit's function not working on Angular Workspace #14413

Closed
dianjuar opened this issue Jan 17, 2023 · 3 comments · Fixed by #15296
Closed

readTargetOptions devkit's function not working on Angular Workspace #14413

dianjuar opened this issue Jan 17, 2023 · 3 comments · Fixed by #15296
Assignees
Labels
outdated scope: angular Issues related to Angular support in Nx scope: devkit type: bug

Comments

@dianjuar
Copy link
Contributor

Current Behavior

readTargetOptions from @nrwl/devkit is triggering an error on Angular Workspaces.

Debugging the code, the problem is because context.projectGraph.nodes is empty, and when it's trying to execute context.projectGraph.nodes[project].data is causes an error because data doesn't exist on undefined.

image

Expected Behavior

It should be able to call readTargetOptions without any problem as it was doing on previous versions

Github Repo

https://github.com/bikecoders/ngx-deploy-npm

Steps to Reproduce

You will need to run an Nx Plugin executor on an Angular Workspace. That executor must use the function @nrwl/devkit/readTargetOptions.

I have a simple script to test this behavior on ngx-deploy-npm, you can use it to reproduce the problem quickly

  1. Clone the repo https://github.com/bikecoders/ngx-deploy-npm
    • git clone https://github.com/bikecoders/ngx-deploy-npm
  2. Step on the branch with the problematic nx version
    • git checkout migrate-nx-15-4
  3. Install new nx version with the issue
    • yarn install
  4. Build the plubin
    • npx build
  5. Execute the Script to test the plugin on an Angular Workspace
    • ./tools/create-angular-workspace.sh

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 18.12.1
   OS   : darwin x64
   yarn : 1.22.15
   
   nx : 15.5.1
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.5.1
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.5.1
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.5.1
   @nrwl/js : 15.5.1
   @nrwl/linter : 15.5.1
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : 15.5.1
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : Not Found
   @nrwl/workspace : 15.5.1
   @nrwl/vite : Not Found
   typescript : 4.9.3
   ---------------------------------------
   Local workspace plugins:
         ngx-deploy-npm
   ---------------------------------------
   Community plugins:
         @jscutlery/semver: 2.29.3

Failure Logs

TypeError: Cannot read properties of undefined (reading 'data')
    at readTargetOptions (/Users/dianjuar/Documents/programing/ngx-deploy-npm/repo/node_modules/@nrwl/devkit/src/executors/read-target-options.js:13:70)
    at /Users/dianjuar/Documents/programing/ngx-deploy-npm/repo/dist/packages/ngx-deploy-npm/src/executors/deploy/actions.js:20:61
    at Generator.next (<anonymous>)
    at fulfilled (/Users/dianjuar/Documents/programing/ngx-deploy-npm/repo/node_modules/tslib/tslib.js:115:62)
Error when trying to publish the library

Additional Information

Failing Log

https://github.com/bikecoders/ngx-deploy-npm/actions/runs/3936177517/jobs/6732526464

Angular Workspace

The Angular Workspace tested has the following characteristics:

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 15.1.1
Node: 18.12.1
Package Manager: npm 8.19.2
OS: darwin x64

Angular: 15.1.0
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1501.1
@angular-devkit/build-angular   15.1.1
@angular-devkit/core            15.1.1
@angular-devkit/schematics      15.1.1
@angular/cli                    15.1.1
@schematics/angular             15.1.1
ng-packagr                      15.1.1
rxjs                            7.8.0
typescript                      4.9.4
@samuelfernandez
Copy link
Contributor

This is blocking a widely used extension to deploy Nx libraries bikecoders/ngx-deploy-npm#454, many depend on it.

Any help would be appreciated 😄

@leosvelperez
Copy link
Member

hey @dianjuar!

Apologies for the delay in addressing this. A PR has been merged that solves this issue for now. The fix is not specific to this issue, but rather a separate fix that happens to address what you are facing.

Just so you know, while most of the Nx DevKit functionality has been working so far in Angular CLI workspaces, the Nx DevKit is not intended to be compatible with or support Angular CLI workspaces. It does contain some utilities to convert Nx generators and executors into Angular CLI schematics and builders, but that's only to consume those in Nx workspaces. That's to allow folks with Nx workspaces migrated from Angular CLI workspaces and using custom schematics and builders to compose existing Nx generators and executors. That way, they don't need to rewrite their schematics and builders using Nx DevKit immediately and can do it whenever they are ready. Those conversion utilities are not meant to produce fully compliant schematics and builders for Angular CLI workspaces. They are meant to produce schematics and builders that can be used in Nx workspaces.

If you need a schematic or builder to be used in Angular CLI workspaces, the safest and recommended thing to do is to write them using the Angular CLI DevKit. You could still potentially use the Nx DevKit, but keeping in mind that things can break without any notice and they shouldn't be considered issues because it's not something we support or intend to support.

@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 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx scope: devkit type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants