4

I recently started getting this error when attempting to create a new component using the angular CLI:

newTree.optimize is not a function

the issued command was:

ng g c test

Googling return only articles from Angular CLI v6.x I have tried uninstalling and reinstalling Angular globally with no luck. Here is my current versioning:

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
Angular CLI: 9.1.0
Node: 12.16.1
OS: win32 x64
Angular:
...
Ivy Workspace:
Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.901.0
@angular-devkit/core         9.1.0
@angular-devkit/schematics   9.1.0
@schematics/angular          9.1.0
@schematics/update           0.901.0
rxjs                         6.5.4

has anyone else found a fix for this?

Thank you!

Kevin192291
  • 1,925
  • 4
  • 26
  • 43

2 Answers2

6

After I upgraded to angular 9, I had 2 packages that were both still at version 0.6.8, They were:

@schematics/angular@9.1.0
@angular-devkit/schematics@9.1.0

For whatever reason, they were not upgraded and it resulted in this error.

Kevin192291
  • 1,925
  • 4
  • 26
  • 43
  • 1
    I had both `@angular-devkit/schematics` and `@angular-devkit/core` on `0.6.8` only in `package-lock.json` didn't event had it installed. Really weird. Installed the dependencies as dev dependencies and everything is solved. Hours lost. – ghaschel May 06 '20 at 21:22
3

The answer above was correct for me but I thought I'd expand on it, in case anyone else runs into the same issue...

@schematics/angular
@angular-devkit/schematics
@angular-devkit/core

were all on 0.6.8. Running the following resolved my issue:

npm install @schematics/angular
npm install @angular-devkit/schematics
npm install @angular-devkit/core

I hope this helps :)

Janey
  • 1,260
  • 3
  • 17
  • 39