-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Cannot run Angular library migration in Nx workspace #20282
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
Comments
Hey @bradley-carestia-jbh ! I know it's been a while and this is still sitting. Would you be able to check if this is still happening in the latest version of Nx? |
Good timing; we're about to do another upgrade cycle @Coly010 . I should be able to test it again in the near future. |
This issue has been automatically marked as stale because no results of retrying on the latest version of Nx was provided within 7 days. |
Just ran my latest migration in version 19, and the issue is still present. My migration starts with:
While the output is just:
Notice the logging statement is not present. |
@bradley-carestia-jbh I'm going to need a reproduction repo, minimal if possible, because I can't reproduce this behaviour. You can see my repo here: https://github.com/Coly010/nx-ng-migration-repro.git The root migrations.json points to the angular schematic migration and i can see it logging correctly: If you clone my repro, make sure to
You may need to change the package.json to remove the |
Hi @Coly010, I have the same problem. The In your reproduction repo, your schematic is called (ie This is because the compiled file of the schematic does not include |
@GuillaumeNury The We can see that log message output in the screenshot above |
@Coly010 if this can help, I just
Here is the
|
@Coly010 here is a repro, with a second schematic: Coly010/nx-ng-migration-repro@main...GuillaumeNury:nx-ng-migration-repro:repro |
Interesting, with your change in place, i'm reproducing the issue |
Ok, I was able to fix it easily enough: ensure
@GuillaumeNury I've pushed an update to the PR (https://github.com/Coly010/nx-ng-migration-repro/pull/2/files) that I created from your change comparison, and here is the result from run-migrations |
@bradley-carestia-jbh Can you confirm if setting |
I'll give it a try! |
@Coly010 it does not work on my machine 🤔 If you look at Since #16259, |
@GuillaumeNury in fact, in that file, CLI is the default check:
If the CLI property exists on the package’s migrations.json file, then return true if it does not equal ‘nx’. If the CLI property does not exist on the package’s migrations.json, use the other methods to try find if it’s an angular migration. I do understand the issue that if you’ve only imported types from angular devkit that after compilation that import will be stripped. |
…cli or schematics #20282
…cli or schematics #20282
Oh, I misread the condition! @Coly010 I tried your fix on |
Yep, which is why we had planned to remove it, but given the fallback logic was flawed, I think it makes sense to keep it for another while to let people have the change to migrate |
…cli or schematics #20282 (#27634) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> We check the CLI property exists and if it's not `nx` we will use the ng compat layer to run the migration. If the CLI property does not exist, we check both if the migration is in the `schematics` object on the `migrations.json` and if the contents of the migration implementation contains an import from `@angular-devkit`. The problem with the fallback is that if only types are imported from `@angular-devkit` the import is stripped from the migration implementation completely. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> We had planned already to remove the fallback of reading the file contents. We had also planned to remove using the `cli` property to determine if the migration needed the `ng compat layer`. However, as the `cli` property is still useful for now for package's that needed some manner to circumvent the flawed fallback logic, let's continue to use it until v21. Log a warning however if the `cli !== 'nx'` and it is placed in the `generators` section of the `migrations.json` to provide ample time for plugin developers to move them to the `schematics` property. Fallback has been updated to whether or not the migration lives in `schematics` and not flawed read file logic. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #20282
…cli or schematics #20282 (#27634) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> We check the CLI property exists and if it's not `nx` we will use the ng compat layer to run the migration. If the CLI property does not exist, we check both if the migration is in the `schematics` object on the `migrations.json` and if the contents of the migration implementation contains an import from `@angular-devkit`. The problem with the fallback is that if only types are imported from `@angular-devkit` the import is stripped from the migration implementation completely. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> We had planned already to remove the fallback of reading the file contents. We had also planned to remove using the `cli` property to determine if the migration needed the `ng compat layer`. However, as the `cli` property is still useful for now for package's that needed some manner to circumvent the flawed fallback logic, let's continue to use it until v21. Log a warning however if the `cli !== 'nx'` and it is placed in the `generators` section of the `migrations.json` to provide ample time for plugin developers to move them to the `schematics` property. Fallback has been updated to whether or not the migration lives in `schematics` and not flawed read file logic. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #20282 (cherry picked from commit 62c6512)
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. |
Current Behavior
We have an internal Angular library with migration scripts for use with
ng update
. The scripts work fine in a standard Angular workspace.When run though
nx migrate
however, the arguments to the script are always undefined. Just like in this StackOverflow post https://stackoverflow.com/questions/76860116/tree-is-undefined-angular-update-schematics-in-a-nx-workspace. Running with FORCE_NG_UPDATE=true results in "Error: This command is not available when running the Angular CLI outside a workspace."To be clear; the
migrations.json
file is generated and appears to run without errors, it just doesn't actually do anything do to the undefined argument.As not everyone using this library is using Nx, we can't make an Nx generator instead; and it seems awkward to maintain both an Angular and Nx version of the migration script. The consuming project is currently on Nx 16.3.1.
Expected Behavior
The library's migration script to run correctly in Nx workspaces.
GitHub Repo
No response
Steps to Reproduce
nx migrate
. Notice not even the log statement works (though a standard console.log does, its definitely calling the function)Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: