nrwl / nx

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

Cannot run @angular/material v15 migrations: Expected a synchronous delegate but got an asynchronous one #14990

Closed kroeder closed 1 year ago

kroeder commented 1 year ago

Current Behavior

I am in the middle of upgrading from Angular + Material v14 to v15. When running the @angular/material migrations, I get the following error

$ nx migrate --runMigrations --verbose

 >  NX   Running 'npm install' to make sure necessary packages are installed
[...]
 >  NX   Failed to run migration-v15 from @angular/material. This workspace is NOT up to date!
 >  NX   Expected a synchronous delegate but got an asynchronous one.

Error: Expected a synchronous delegate but got an asynchronous one.
    at SyncDelegateHost._doSyncCall (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\core\src\virtual-fs\host\sync.js:39:19)
    at SyncDelegateHost.read (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\core\src\virtual-fs\host\sync.js:57:21)
    at LazyFileEntry._load (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:252:80)
    at LazyFileEntry.get content [as content] (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\schematics\src\tree\entry.js:34:55)
    at HostTree.read (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:211:30)
    at getWorkspaceConfigGracefully (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular\cdk\schematics\utils\project-tsconfig-paths.js:24:31)
    at C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular\cdk\schematics\ng-update\devkit-migration-rule.js:51:91
    at callRuleAsync (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\schematics\src\rules\call.js:78:24)
    at C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\schematics\src\rules\call.js:73:40
    at Observable._subscribe (C:\Users\kro\WebstormProjects\nx-migration-bug-reproduction\node_modules\@angular-devkit\schematics\node_modules\rxjs\internal\observable\defer.js:10:21)

I migrated to Nx during Angular 14 and thought I might have missed something. Therefore, I did npx nx@latest migrate --from=nx@14 and it actually found a couple of missing migrations. On top of that, I tried nx repair but without any significant changes - the error still exists.

I had the same issue with some of the Angular 15 migrations (not all) but ignored them because these migrations were irrelevant for me.

Expected Behavior

Run migrations for @angular/material successfully.

GitHub Repo

https://github.com/kroeder/nx-15_7-migration-bug-reproduction

Steps to Reproduce

  1. Clone https://github.com/kroeder/nx-15_7-migration-bug-reproduction
  2. npm install
  3. nx migrate --run-migrations

The output should be

$ nx migrate --run-migrations

 >  NX   Running 'npm install' to make sure necessary packages are installed

up to date, audited 1427 packages in 2s

found 0 vulnerabilities

 >  NX   Running migrations from 'migrations.json'

 >  NX   Failed to run migration-v15 from @angular/material. This workspace is NOT up to date!
 >  NX   Expected a synchronous delegate but got an asynchronous one.
   Pass --verbose to see the stacktrace.

Nx Report

Node : 16.18.0                                           
   OS   : win32 x64                                         
   npm  : 8.19.2                                            

   nx                      : 15.7.0
   @nrwl/jest              : 15.7.0
   @nrwl/linter            : 15.7.0
   @nrwl/workspace         : 15.7.0
   @nrwl/angular           : 15.7.0
   @nrwl/cli               : 15.7.0
   @nrwl/cypress           : 15.7.0
   @nrwl/devkit            : 15.7.0
   @nrwl/eslint-plugin-nx  : 15.7.0
   @nrwl/js                : 15.7.0
   @nrwl/tao               : 15.7.0
   @nrwl/webpack           : 15.7.0
   @nrwl/nx-cloud          : 15.0.3
   typescript              : 4.8.4

Failure Logs

No response

Additional Information

No response

amkoehler commented 1 year ago

I'm experiencing this too. Same behavior for nx migrate latest (for 15.7.0) and nx migrate 15.6.3.

Khaldor48 commented 1 year ago

+1 And I cannot even update with using ng command.

First I had to do in PowerShell v7.3.2 $Env:FORCE_NG_UPDATE = "true";

Then I get response Using Nx to run Angular CLI commands is deprecated and will be removed in a future version. To run Angular CLI commands, use \ng`. Error: This command is not available when running the Angular CLI outside a workspace. `

Maybe it's somehow related, maybe it's not. Adding just for sake of more info

lukashlobil commented 1 year ago

This also happens when I try to run nx generate schematics

Ocbeckoo commented 1 year ago

As is mentioned here. I´m struggling with the same problem. Hope this will be fixed soon.

Flusinerd commented 1 year ago

I've looked into this yesterday a bit and found out this, maybe this helps someone:

The migration is trying to read a angular.json at the root using the virtualFs from the angular-cdk. Nx does have an adapter that creates a scope for the virtualFs. Since NX repos don't have a angular.json at the root of the project and instead have multiple project.json files it merges into a "fake" angular.json file at the root that migrations run against.

This is where I got stuck because it looked like the adapter was not beeing called for me, or I was looking at the wrong source.

leosvelperez commented 1 year ago

Hey all! Thanks for reporting this!

I'm sorry you're facing this issue. We are fully aware of it and we are troubleshooting it. We'll have a fix for it as soon as possible.

rawatanimesh commented 1 year ago

I am having the same issue. I am migrating my repo to angular version 13.

jpv-os commented 1 year ago

Same problem when migrating from NX 13 to 14

---------------------------------------------------------
Ran remove-library-generator-style-default from @nrwl/angular
  Remove the default for the invalid 'style' option for the library generator if configured.

  UPDATE nx.json
---------------------------------------------------------

 >  NX   Failed to run migration-v13 from @angular/cdk. This workspace is NOT up to date!

 >  NX   Expected a synchronous delegate but got an asynchronous one.

   Node : 14.21.2
   OS   : darwin arm64
   npm  : 6.14.17

   nx : 14.0.0
   @nrwl/angular : 14.0.0
   @nrwl/cypress : 14.0.0
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.0.0
   @nrwl/eslint-plugin-nx : 14.0.0
   @nrwl/express : Not Found
   @nrwl/jest : 14.0.0
   @nrwl/js : 14.0.0
   @nrwl/linter : 14.0.0
   @nrwl/nest : 14.0.0
   @nrwl/next : Not Found
   @nrwl/node : 14.0.0
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.0.0
   @nrwl/web : Not Found
   @nrwl/workspace : 14.0.0
   typescript : 4.6.4
   rxjs : 6.5.5
   ---------------------------------------
   Community plugins:
         apollo-angular: 2.6.0
IsaBartkowiak commented 1 year ago

Having the same issue from v14 to v15

BenLune commented 1 year ago

I also have this problem, from v14 to v15. Thanks for your help.

petro-konopelko commented 1 year ago

I'm also having such issue during the migration from angular 13 to angular 14 Is this going to be fixed in 14 version of nx?

NX Report complete - copy this into the issue template

Node : 16.13.2 OS : win32 x64 npm : 8.19.1

nx : 14.8.6 @nrwl/angular : 14.8.6 @nrwl/cypress : 14.8.6 @nrwl/detox : Not Found @nrwl/devkit : 14.8.6 @nrwl/esbuild : Not Found @nrwl/eslint-plugin-nx : 14.8.6 @nrwl/expo : Not Found @nrwl/express : Not Found @nrwl/jest : 14.8.6 @nrwl/js : 14.8.6 @nrwl/linter : 14.8.6 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/nx-cloud : Not Found @nrwl/nx-plugin : Not Found @nrwl/react : Not Found @nrwl/react-native : Not Found @nrwl/rollup : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.8.6 @nrwl/web : Not Found @nrwl/webpack : 14.8.6 @nrwl/workspace : 14.8.6 typescript : 4.8.4

Local workspace plugins:

Community plugins: ngx-bootstrap: 9.0.0 rxjs: 6.6.7 @compodoc/compodoc: 1.1.19 @storybook/angular: 6.4.22 @testing-library/angular: 10.11.1 ng-mocks: 14.6.0

petro-konopelko commented 1 year ago

What is interesting is that Command failed: D:\Users\user-name\AppData\Local\Temp\1\tmp-18108-U70nmDqTGk4V\node_modules\.bin\nx _migrate --run-migrations --verbose By that path, package.json has refference to the latest version of nx in node_modules. And in package-lock.json it has reference to nx@15.7.1

"nx": {
      "version": "15.7.1",
      "resolved": "https://pkgs.dev.azure.com/FS-RC/_packaging/wizng/npm/registry/nx/-/nx-15.7.1.tgz",
      "integrity": "sha1-5NiBMHkH8ma2mO1NYa+bmY+qVOs=",
      "requires": {
        "@nrwl/cli": "15.7.1",
        "@nrwl/nx-darwin-arm64": "15.7.1",
        "@nrwl/nx-darwin-x64": "15.7.1",
        "@nrwl/nx-linux-arm-gnueabihf": "15.7.1",
        "@nrwl/nx-linux-arm64-gnu": "15.7.1",
        "@nrwl/nx-linux-arm64-musl": "15.7.1",
        "@nrwl/nx-linux-x64-gnu": "15.7.1",
        "@nrwl/nx-linux-x64-musl": "15.7.1",
        "@nrwl/nx-win32-arm64-msvc": "15.7.1",
        "@nrwl/nx-win32-x64-msvc": "15.7.1",
        "@nrwl/tao": "15.7.1",
        "@parcel/watcher": "2.0.4",
        "@yarnpkg/lockfile": "^1.1.0",
        "@yarnpkg/parsers": "^3.0.0-rc.18",
        "@zkochan/js-yaml": "0.0.6",
        "axios": "^1.0.0",
        "chalk": "^4.1.0",
        "cli-cursor": "3.1.0",
        "cli-spinners": "2.6.1",
        "cliui": "^7.0.2",
        "dotenv": "~10.0.0",
        "enquirer": "~2.3.6",
        "fast-glob": "3.2.7",
        "figures": "3.2.0",
        "flat": "^5.0.2",
        "fs-extra": "^11.1.0",
        "glob": "7.1.4",
        "ignore": "^5.0.4",
        "js-yaml": "4.1.0",
        "jsonc-parser": "3.2.0",
        "lines-and-columns": "~2.0.3",
        "minimatch": "3.0.5",
        "npm-run-path": "^4.0.1",
        "open": "^8.4.0",
        "semver": "7.3.4",
        "string-width": "^4.2.3",
        "strong-log-transformer": "^2.1.0",
        "tar-stream": "~2.2.0",
        "tmp": "~0.2.1",
        "tsconfig-paths": "^4.1.2",
        "tslib": "^2.3.0",
        "v8-compile-cache": "2.3.0",
        "yargs": "^17.6.2",
        "yargs-parser": "21.1.1"
      }
    }
DimitriLib commented 1 year ago

I am also having the same issue when migrating from nx/angular 13 to 14 angular/cdk and angular/material

  NX   Failed to run migration-v14 from @angular/cdk. This workspace is NOT up to date! >  NX   Expected a synchronous delegate but got an asynchronous one.

leosvelperez commented 1 year ago

hey all! The fix has been merged and it will be released in a patch version. Once released, the issue would be solved for all versions of Nx. The migrate command always installs the latest version of Nx to collect and run migrations, that's why the issue happened to multiple versions.

Keep an eye on the releases to get the fix!

DimitriLib commented 1 year ago

hey all! The fix has been merged and it will be released in a patch version. Once released, the issue would be solved for all versions of Nx. The migrate command always installs the latest version of Nx to collect and run migrations, that's why the issue happened to multiple versions.

Keep an eye on the releases to get the fix!

I was running nx migrate 15.1.1 not the latest when upgrading from angular 13 to 14 If i am running nx migrate latest it would pull scripts for angular 15, not 14

After fix what command do i need to execute to get angular 14 version with nx 15?

Please advise

Thank you

leosvelperez commented 1 year ago

I was running nx migrate 15.1.1 not the latest when upgrading from angular 13 to 14 If i am running nx migrate latest it would pull scripts for angular 15, not 14

@DimitriLib it doesn't matter to which version you're migrating to, nx migrate always install the latest nx in a temporary location and uses it to collect and run migrations. So, regardless of the version you're migrating to, the executable that runs to do the migration is on the latest version of Nx. That's why all the versions got the issue that was introduced in 15.7.0.

As mentioned in the previous comment, the fix will solve the issue for all migrations from and to any version.

DimitriLib commented 1 year ago

I was running nx migrate 15.1.1 not the latest when upgrading from angular 13 to 14 If i am running nx migrate latest it would pull scripts for angular 15, not 14

@DimitriLib it doesn't matter to which version you're migrating to, nx migrate always install the latest nx in a temporary location and uses it to collect and run migrations. So, regardless of the version you're migrating to, the executable that runs to do the migration is on the latest version of Nx. That's why all the versions got the issue that was introduced in 15.7.0.

As mentioned in the previous comment, the fix will solve the issue for all migrations from and to any version.

Thank you for quick response. Do you have a timeframe when patch will be released? We are in the middle of migration and need to make a decision today/tomorrow if roll it back or continue forward.

2 scripts fail: { "version": "14.0.0-0", "description": "Updates the Angular CDK to v14", "factory": "./ng-update/index#updateToV14", "package": "@angular/cdk", "name": "migration-v14" }, { "version": "14.0.0-0", "description": "Updates the Angular Material to v14", "factory": "./ng-update/index#updateToV14", "package": "@angular/material", "name": "migration-v14" }

Would that be possible to update code manually for failed scripts?

After upgrade getting error when generating library, can you please help and let me know reason why it can be happening?

PS C:\Users\dimitri.liberman\nx14upgrade\tps-client> nx g @nrwl/angular:library my-ui-lib --tags=ui --dry-run            >  NX  Generating @nrwl/angular:library [NX] Angular devkit called writeWorkspace, this may have had unintended consequences in angular.json [NX] Double check angular.json before proceeding Skipping my-ui-lib since libs\my-ui-lib\project.json already exists. UPDATE angular.json CREATE libs/my-ui-lib/README.md CREATE libs/my-ui-lib/tsconfig.lib.json CREATE libs/my-ui-lib/tsconfig.spec.json CREATE libs/my-ui-lib/src/index.ts CREATE libs/my-ui-lib/src/lib/my-ui-lib.module.ts CREATE libs/my-ui-lib/tsconfig.json CREATE libs/my-ui-lib/project.json UPDATE tsconfig.base.json CREATE libs/my-ui-lib/jest.config.ts CREATE libs/my-ui-lib/src/test-setup.ts CREATE libs/my-ui-lib/.eslintrc.json

nickn418 commented 1 year ago

@DimitriLib Similar situation here, I found the NX_MIGRATE_USE_NEXT env var that did the trick, uses the beta version of nx but no issues for my angular app: NX_MIGRATE_USE_NEXT=true npx nx migrate --run-migrations --verbose

Khaldor48 commented 1 year ago

Hi, thank you for taking quick actions.

I don't know if it's already present in 15.8.0-beta.1, but when I tried to test to migrate to this version I got the same error

> NX Failed to run migration-v15 from @angular/cdk. This workspace is NOT up to date!

> NX Expected a synchronous delegate but got an asynchronous one.

l3onh4rd commented 1 year ago

Hi, thank you for taking quick actions.

I don't know if it's already present in 15.8.0-beta.1, but when I tried to test to migrate to this version I got the same error

> NX Failed to run migration-v15 from @angular/cdk. This workspace is NOT up to date!

> NX Expected a synchronous delegate but got an asynchronous one.

Same here. When to expect the 15.8.0 release?

iliakan commented 1 year ago

Subscribing =)

frobean commented 1 year ago

This issue seems worthy of a patch release on its own. Please don't take this as a complaint. I'm very happy that it was fixed so quickly! I'm just anxious to get the fix into my hands. :)

ziacik commented 1 year ago

Omg I'm really getting tired of this

kroeder commented 1 year ago

I need to quote this again

hey all! The fix has been merged and it will be released in a patch version

Within 24 hours there was a response to this issue, only a few days to merge a fix and all we now need to do is to have a little bit of patience until it gets released 🙏

Thanks for fixing this so fast! 🙂

IBot18 commented 1 year ago

First thing first, thx for fixing this issue so fast. The Migration step works now, however if i run the migration step from Angular Material (https://material.angular.io/guide/mdc-migration#2-run-the-migration-tool) which apparantly is needed to complete the Material Migration from Legacy Version 14 to 15 it again fails with the same error.

ng generate @angular/material:mdc-migration results in

SynchronousDelegateExpectedException [Error]: Expected a synchronous delegate but got an asynchronous one.                                         
    at SyncDelegateHost._doSyncCall (C:\[...]node_modules\@angular-devkit\core\src\virtual-fs\host\sync.js:39:19)                       
    at SyncDelegateHost.read (C:\[...]\node_modules\@angular-devkit\core\src\virtual-fs\host\sync.js:57:21)                              
    at LazyFileEntry._load (C:\[...]\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:252:80)                               
    at LazyFileEntry.get content [as content] (C:\[...]\node_modules\@angular-devkit\schematics\src\tree\entry.js:34:55)                 
    at HostTree.read (C:\[...]\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:211:30)                                     
    at getWorkspaceConfigGracefully (C:\[...]\node_modules\@angular\cdk\schematics\utils\project-tsconfig-paths.js:24:31)                
    at SchematicImpl.<anonymous> (C:\[...]\node_modules\@angular\material\schematics\ng-generate\mdc-migration\index_bundled.js:23448:81)
    at Generator.next (<anonymous>)                                                                                                                
    at C:\[...]\node_modules\@angular\material\schematics\ng-generate\mdc-migration\index_bundled.js:73:61                               
    at new Promise (<anonymous>)                                                                                                                   

  > NX   Expected a synchronous delegate but got an asynchronous one.

May this problem be connected?

leosvelperez commented 1 year ago

hey @IBot18!

The error is the same, but it's triggered by a different command which is run differently. Please open a new issue with a repro and tag me. I'll take it from there.

iliakan commented 1 year ago

Was this, by chance, fixed in 15.7.2?

vosuyak commented 1 year ago

The latest push from @leosvelperez resolved this issue.

  1. npm i nx@15.8.5 --force
  2. nx generate @angular/material:mdc-migration
  3. changes all .scss references of Material
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.