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

newTree.optimize is not a function - Error with ng g lib #640

Closed
xmlking opened this issue Jul 23, 2018 · 13 comments · Fixed by #650
Closed

newTree.optimize is not a function - Error with ng g lib #640

xmlking opened this issue Jul 23, 2018 · 13 comments · Fixed by #650

Comments

@xmlking
Copy link
Contributor

xmlking commented Jul 23, 2018

Command

ng generate lib mylib --dry-run

Error

newTree.optimize is not a function

Env

./node_modules/.bin/nx --version
6.1.1

 ng -v

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

Angular CLI: 6.1.0-rc.3
Node: 10.5.0
OS: darwin x64
Angular: 6.1.0-rc.3
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.7.0-rc.3
@angular-devkit/build-angular      0.7.0-rc.3
@angular-devkit/build-ng-packagr   0.7.0-rc.3
@angular-devkit/build-optimizer    0.7.0-rc.3
@angular-devkit/build-webpack      0.7.0-rc.3
@angular-devkit/core               0.6.8
@angular-devkit/schematics         0.6.8
@angular/cdk                       6.4.0
@angular/cdk-experimental          6.4.0
@angular/flex-layout               6.0.0-beta.16
@angular/material                  6.4.0
@angular/material-moment-adapter   6.4.0
@angular/pwa                       0.6.8
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.1.0-rc.3
@schematics/angular                0.6.8
@schematics/update                 0.7.0-rc.3
ng-packagr                         4.0.0
rxjs                               6.2.2
typescript                         2.9.2
webpack                            4.9.2
@javahaxxor
Copy link

javahaxxor commented Jul 25, 2018

it seems to be a problem with angular-cli. Last version working was @angular/cli@6.1.0-rc.0, see angular/angular-cli#11532

@gerold-penz
Copy link

I have the same problem.

@xmlking
Copy link
Contributor Author

xmlking commented Jul 26, 2018

6.1.0 cli is released. Hope nx support it soon.

@jviaches
Copy link

jviaches commented Jul 26, 2018

Same here with ionic generate component myComponent

This resolved an issue: npm install --save-dev @angular/cli@6.1.0-rc.0

@csotomon
Copy link

csotomon commented Jul 27, 2018

I tried the @jviaches solution, and worked. so the bug is in @angular/cli > 6.1.0-rc.0

@phpfs
Copy link

phpfs commented Jul 27, 2018

Got the same issue :/

@bjanderson
Copy link

bjanderson commented Jul 28, 2018

Hoping this helps whoever is hunting this bug down...

This is probably a problem with @angular-devkit/schematics(-cli).

I'm creating my own schematics and I have @angular/cli@latest installed but I get this error if I install any version of the devkit after @angular-devkit/schematics-cli@0.7.0-rc.0

My schematics project package.json has the following installed
"@angular-devkit/core": "0.6.8",
"@angular-devkit/schematics": "0.6.8",
"@angular/cli": "6.1.1",

@ghost
Copy link

ghost commented Jul 29, 2018

Getting this error so reverted back to 6.1.0-rc.0, now getting "Could not find an NgModule. Use the skip-import option to skip importing in NgModule"

Beginning to dig into this now...following here hoping for a resolution.

Thx.

@ghost
Copy link

ghost commented Jul 29, 2018

Deleting node_modules and running yarn seems to have fixed the "Could not find an NgModule" error.

@vsavkin
Copy link
Member

vsavkin commented Jul 29, 2018

Angular CLI 6.1 will be supported by Nx 6.2, which is going to be released soon.

@elmiguel
Copy link

elmiguel commented Jul 30, 2018

ng -v

`
$ ng -v
Angular CLI: 6.1.1
Node: 10.5.0
OS: linux x64
Angular: 6.1.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker

Package Version

@angular-devkit/architect 0.7.1
@angular-devkit/build-angular 0.7.1
@angular-devkit/build-optimizer 0.7.1
@angular-devkit/build-webpack 0.7.1
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.1.1
@angular/pwa 0.7.1
@ngtools/webpack 6.1.1
@schematics/angular 0.6.8
@schematics/update 0.7.1
rxjs 6.2.2
typescript 2.9.2
webpack 4.9.2

`

Reverting back to 6.1.0-rc.0 does not seem to work. For me at least.

Result after reverting and redoing yarn (after deleting node_modules):

$ ng g lib common-core
ERROR! common-core/karma.conf.js does not exist..
ERROR! common-core/ng-package.json does not exist..
ERROR! common-core/ng-package.prod.json does not exist..
ERROR! common-core/package.json does not exist..
ERROR! common-core/tsconfig.lib.json does not exist..
ERROR! common-core/tsconfig.spec.json does not exist..
ERROR! common-core/tslint.json does not exist..
ERROR! common-core/src/index.ts does not exist..
ERROR! common-core/src/test.ts does not exist..
ERROR! common-core/src/lib/common-core.component.ts does not exist..
ERROR! common-core/src/lib/common-core.module.ts does not exist..
ERROR! libs/common-core/src/lib/common-core.module.ts does not exist..
ERROR! libs/common-core/src/index.ts does not exist..
ERROR! libs/common-core/tsconfig.lib.json does not exist..
ERROR! libs/common-core/tsconfig.spec.json does not exist..
ERROR! libs/common-core/tslint.json does not exist..
ERROR! libs/common-core/karma.conf.js does not exist..
The Schematic workflow failed. See above.

Any patches/workarounds in the meantime?

@elmiguel
Copy link

elmiguel commented Jul 30, 2018

Update: I uninstalled nrwl/schematics and the angular/cli from global then reinstalled. Deleted the project folder and recreated the project using the create-nx-workspace command. I have to refer to 0.6.8 in the ng add @angular/pwa@0.6.8 in order to add the pwa. That worked correctly. Once that was all done, I used the ng g lib common-ui (instead of common-core; mainly it seems semantically better) and it seems to be working.

I did notice this its was generating the lib:

warning " > @ngrx/effects@5.2.0" has incorrect peer dependency "@angular/core@^5.0.0".
warning " > @ngrx/effects@5.2.0" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @ngrx/router-store@5.2.0" has incorrect peer dependency "@angular/common@^5.0.0".
warning " > @ngrx/router-store@5.2.0" has incorrect peer dependency "@angular/core@^5.0.0".
warning " > @ngrx/router-store@5.2.0" has incorrect peer dependency "@angular/router@^5.0.0".
warning " > @ngrx/router-store@5.2.0" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @ngrx/store@5.2.0" has incorrect peer dependency "@angular/core@^5.0.0".
warning " > @ngrx/store@5.2.0" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @ngrx/store-devtools@5.2.0" has incorrect peer dependency "rxjs@^5.5.0".
warning " > @nrwl/schematics@6.1.1" has unmet peer dependency "@schematics/angular@^0.6.0".
warning " > @nrwl/schematics@6.1.1" has unmet peer dependency "@angular-devkit/schematics@^0.6.0".

I noticed earlier and updated each peer dependency and that is where I think the issues started to occur. Do you think that when trying to update to the correct peers, there is a chance the link mismatching?

I did not do the updates to the peers this time and everything seems to work so far.

@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 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants