AngularJS6 コンポーネント生成コマンドに失敗したときの対処法
AngularJS始めたばかりで、まだまだ苦戦中。。。 すでにAngularJS6が出たので、最新バージョンで試したら、急にngコマンドでコンポーネントが作成できなくなったので、その対処法の備忘録です。
バージョン情報
Angular CLI: 6.0.8 Node: 10.6.0 OS: darwin x64 Angular: 6.0.7 ... 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 @angular/cdk 6.3.3 @angular/cli 6.0.8 @angular/material 6.3.3 @ngtools/webpack 6.0.8 @schematics/angular 0.6.8 @schematics/update 0.6.8 rxjs 6.2.1 typescript 2.7.2 webpack 4.8.3
発生したエラー
ng generate component dashboard --style=scss Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
調査
試したこと
angular.json
のproject-name-e2e
の部分をごそっと消してみる
無事生成される
angular.json
のproject-name-e2e
のroot
を変更
"project-name-e2e": { - "root": "", + "root": "e2e/", "sourceRoot": "e2e", "projectType": "application", "architect": { }
無事生成される
考察
ng generateのターゲットがe2e用の方を向いていたのではないだろうか
試しにe2eのプロジェクトを指定してみたところ、同じようなエラーが発生した。
ng generate component issues --style=scss --project=project-name-e2e Could not find an NgModule. Use the skip-import option to skip importing in NgModule.
e2e用を作成する場合は、skip-import
をする
ng generate component issues --style=scss --project=wotatima-ui-e2e --skip-import=true CREATE e2e/app/issues/issues.component.scss (0 bytes) CREATE e2e/app/issues/issues.component.html (25 bytes) CREATE e2e/app/issues/issues.component.spec.ts (628 bytes) CREATE e2e/app/issues/issues.component.ts (270 bytes)
しかし、default-project
は変えてないのに、バージョンアップしたらなぜにe2eの方を作成しようとしたんだろう。。。謎だ