Search code examples
angularangular-materialangular-cliangular-cdk

Angular Material v15 upgrade - failed: ts.getDecorators is not a function


Im trying to upgrade a library and showcase project to Angular Material v15. No issues updating to Angular, but when I run ng update @angular/material@15 --force I get the error Migration failed: ts.getDecorators is not a function This is the full message enter image description here This is all that is in the error log:

[error] TypeError: ts.getDecorators is not a function
    at ComponentResourceCollector._visitClassDeclaration (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\@angular\cdk\schematics\update-tool\component-resource-collector.js:40:31)
    at ComponentResourceCollector.visitNode (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\@angular\cdk\schematics\update-tool\component-resource-collector.js:36:18)
    at visitNodeAndCollectResources (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\@angular\cdk\schematics\update-tool\index.js:83:31)
    at visitNodes (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\typescript\lib\typescript.js:30672:30)
    at Object.forEachChild (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\typescript\lib\typescript.js:30951:24)
    at visitNodeAndCollectResources (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\@angular\cdk\schematics\update-tool\index.js:82:16)
    at C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\@angular\cdk\schematics\update-tool\index.js:92:17
    at Array.forEach (<anonymous>)
    at UpdateProject.migrate (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\@angular\cdk\schematics\update-tool\index.js:87:21)
    at runMigrations (C:\my-project\Lib-my-project-Grid\my-projectGrid\node_modules\@angular\cdk\schematics\ng-update\devkit-migration-rule.js:122:42)

**Additional info: I have to use --force flag because as of the time of this question @angular/flex-layount v15 still has a PR Pending. Ng update fails because of peer-dependency.

Additionally when I try to run ng update again I get the message Package '@angular/material' is already up to date. which is reflected in my package.json.
However when i try and run migration only, after npm install, (ng update @angular/material@15 --migrate-only) I get the error package is not installed

This is my package.json in case it helps:

{
  "name": "lib-omega-grid",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "build_lib": "npm run set_node_max_size && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build my-lib-grid-lib --configuration=production",
    "set_node_max_size": "set NODE_OPTIONS=--max-old-space-size=8192",
    "npm_pack": "cd dist/my-lib-grid-lib && npm pack",
    "publish": "cd dist/my-lib-grid-lib && npm publish --ignore-scripts",
    "package": "npm run build_lib && npm run npm_pack",
    "package_no": "npm run build_lib && npm run npm_pack",
    "clean": "rmdir /s /q node_modules",
    "package_test": "npm run build_lib && npm run npm_pack"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^15.0.3",
    "@angular/cdk": "^15.0.2",
    "@angular/common": "^15.0.3",
    "@angular/compiler": "^15.0.3",
    "@angular/core": "^15.0.3",
    "@angular/elements": "^15.0.3",
    "@angular/flex-layout": "14.0.0-beta.40",
    "@angular/forms": "^15.0.3",
    "@angular/localize": "^15.0.3",
    "@angular/material": "^15.0.2",
    "@angular/material-moment-adapter": "^15.0.2",
    "@angular/platform-browser": "^15.0.3",
    "@angular/platform-browser-dynamic": "^15.0.3",
    "@angular/router": "^15.0.3",
    "@biesbjerg/ngx-translate-extract": "7.0.3",
    "@danielmoncada/angular-datetime-picker": "^15.0.0",
    "@microsoft/signalr": "5.0.11",
    "@ngrx/effects": "^15.0.0",
    "@ngrx/store": "^15.0.0",
    "@ngx-translate/core": "~14.0.0",
    "@ngx-translate/http-loader": "~7.0.0",
    "@my-lib/notifications": "9.0.4",
    "@splitsoftware/splitio": "10.22.2",
    "@thebespokepixel/es-tinycolor": "^2.1.1",
    "@types/express": "^4.17.13",
    "core-js": "3.25.0",
    "document-register-element": "1.14.10",
    "file-saver": "2.0.5",
    "html2canvas": "^1.0.0-rc.7",
    "jspdf": "^2.4.0",
    "jspdf-autotable": "^3.5.23",
    "logrocket": "3.0.1",
    "material-community-components": "10.0.0",
    "material-design-icons": "3.0.1",
    "material-design-icons-iconfont": "6.1.0",
    "moment": "2.29.4",
    "moment-timezone": "0.5.37",
    "oidc-client": "1.11.5",
    "rxjs": "~7.5.0",
    "tinycolor2": "^1.4.2",
    "tslib": "^2.3.0",
    "xlsx": "^0.17.5",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.0.3",
    "@angular-devkit/core": "^15.0.3",
    "@angular-eslint/builder": "14.0.2",
    "@angular-eslint/eslint-plugin": "14.0.2",
    "@angular-eslint/eslint-plugin-template": "14.0.2",
    "@angular-eslint/schematics": "14.0.2",
    "@angular-eslint/template-parser": "14.0.2",
    "@angular/cli": "~15.0.3",
    "@angular/compiler-cli": "^15.0.3",
    "@angular/language-service": "^15.0.3",
    "@types/html2canvas": "0.0.36",
    "@types/jasmine": "~4.0.0",
    "@types/jasminewd2": "~2.0.8",
    "@typescript-eslint/eslint-plugin": "5.36.1",
    "@typescript-eslint/parser": "5.36.1",
    "eslint": "^8.18.0",
    "eslint-plugin-import": "latest",
    "eslint-plugin-jsdoc": "latest",
    "eslint-plugin-prefer-arrow": "latest",
    "jasmine-core": "~4.3.0",
    "jasmine-spec-reporter": "7.0.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "ng-packagr": "^14.2.0",
    "typescript": "~4.7.2"
  }
}

Solution

  • After discussion on the Angular Discord channel it was suggested that I update my typescript version to 4.8.2. After doing that the material upgrade and migration worked!

    https://discord.com/channels/748677963142135818/1051985021562523778/1051985021562523778