1

Estou começando com angular e acabei me deparando com erro muito estranho ao tentar executar o comando:

ng generate @angular/material:material-nav --name nav-menu

ele me aprensenta a seguinte satck:

 Collection "@angular/material" cannot be resolved.
 Error: Collection "@angular/material" cannot be resolved.
     at NodeModulesEngineHost._resolveCollectionPath (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:88:15)
at NodeModulesEngineHost.createCollectionDescription (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:106:27)
at SchematicEngine._createCollectionDescription (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/src/engine/engine.js:78:40)
at SchematicEngine.createCollection (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/src/engine/engine.js:71:43)
at Object.getCollection (/usr/local/lib/node_modules/@angular/cli/utilities/schematics.js:28:31)
at GenerateCommand.getOptions (/usr/local/lib/node_modules/@angular/cli/models/schematic-command.js:193:41)
at GenerateCommand.<anonymous> (/usr/local/lib/node_modules/@angular/cli/commands/generate.js:38:53)
at Generator.next (<anonymous>)
at /usr/local/lib/node_modules/@angular/cli/commands/generate.js:7:71
at new Promise (<anonymous>)

Já tentei reinstalar o @angular/cli e também apagar a pasta node_modules, mas nada adiantou.

Estou no ambiente:

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


 Angular CLI: 6.0.8
 Node: 8.11.2
 OS: darwin x64
 Angular: 6.0.6
 ... animations, common, compiler, compiler-cli, core, forms
 ... http, language-service, platform-browser
 ... platform-browser-dynamic, router

 Package                           Version
 -----------------------------------------------------------
 @angular-devkit/architect         0.6.8
 @angular-devkit/build-angular     0.6.8
 @angular-devkit/build-optimizer   0.6.8
 @angular-devkit/core              0.6.8
 @angular-devkit/schematics        0.6.8 (cli-only)
 @angular/cdk                      6.3.1
 @angular/flex-layout              6.0.0-beta.16
 @angular/material                 6.3.1
 @ngtools/webpack                  6.0.8
 @schematics/angular               0.6.8 (cli-only)
 @schematics/update                0.6.8 (cli-only)
 rxjs                              6.2.1
 typescript                        2.7.2
 webpack                           4.8.3

1 Resposta 1

0

Tive o mesmo problema agora e achei a solução aqui:

https://github.com/angular/material2/issues/11836

Basicamente use:

ng add @angular/[email protected]

Para adicionar a versão 6.2.1 em vez de adicionar a última. Por que a última versão (6.3.0) está com esse bug que você encontrou.

1

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .