中安拓也のブログ

プログラミングについて書くブログ

【障害メモ】[Angular CLI]Invalid rule result: Instance of class Promise.

発生した障害

Angular v8のプロジェクトでAngular CLIのng generateコマンドを使用してコンポーネントを作成しようとしたら、Invalid rule result: Instance of class Promise.というエラーメッセージが表示された。

$ ng g component component/forder-list-header
Invalid rule result: Instance of class Promise.

障害が発生した環境

$ ng version

Angular CLI: 7.3.6
Node: 8.11.3
OS: darwin x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.20
@angular-devkit/build-angular     0.12.4
@angular-devkit/build-optimizer   0.12.4
@angular-devkit/build-webpack     0.12.4
@angular-devkit/core              8.3.20
@angular-devkit/schematics        8.3.20
@angular/cdk                      7.3.7
@angular/cli                      8.3.20
@angular/fire                     5.2.3
@angular/material                 7.3.7
@ngtools/webpack                  7.2.4
@schematics/angular               8.3.20
@schematics/update                0.803.20
rxjs                              6.5.3
typescript                        3.5.3
webpack                           4.28.4

障害の改修手順

下記の二つのステップを通じて障害を改修した。

  1. Angular CLIの最新版をインストール
  2. Node.jsのバージョン10.9以上をインストール

Angular CLIの最新版をインストール

まず、Angular CLI(@angular/cli)の最新版のnpmパッケージをグローバルインストールする。

$ npm install @angular/cli -g

/usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng

> @angular/cli@8.3.20 postinstall /usr/local/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js

+ @angular/cli@8.3.20
added 83 packages, removed 196 packages, updated 61 packages and moved 2 packages in 12.383s
(base) MacBook-Pro-4:concept takuya$ 
(base) MacBook-Pro-4:concept takuya$ ng g component component/forder-list-header
You are running version v8.11.3 of Node.js, which is not supported by Angular CLI 8.0+.
The official Node.js version that is supported is 10.9 or greater.

Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.
(base) MacBook-Pro-4:concept takuya$ ng g component component/forder-list-header
You are running version v8.11.3 of Node.js, which is not supported by Angular CLI 8.0+.
The official Node.js version that is supported is 10.9 or greater.

Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.

Node.jsのバージョン10.9以上をインストール

Angular CLIのインストールを実施すると上記の通り、「Node.jsのバージョンを10.9以上にしなさいと」いうメッセージが表示されるので、 続いてNode.jsのインストールを実施する。

過去のTypeScript/JavaScriptのプロジェクトが動かなくなったら困るので、Node.jsのバージョン管理ツールであるnを使ってNodeのアップグレードを実施する。

まず、npm install n -gコマンドでnのグローバルインストールを実施。

$ npm install n -g

n --stablen --latestコマンドで安定版と最新版のバージョンを確認

$ n --stable
12.13.1
(base) MacBook-Pro-4:concept takuya$ n --latest
13.3.0

安定版でバージョンの条件を十分満たしていたので、n stableコマンドで安定版の方のNodeをインストールする

$ n stable

node --versionコマンドでNodeのバージョンを確認すると、正常に安定版のバージョンがインストールされていることがわかる。

$ node --version
v12.13.1

動作確認

上記の手順を踏んだ後でng generateコマンドを実行すると、正常に処理が完了してコンポーネントも作成された。

$ ng g component component/forder-list-header
CREATE src/app/component/forder-list-header/forder-list-header.component.scss (0 bytes)
CREATE src/app/component/forder-list-header/forder-list-header.component.html (33 bytes)
CREATE src/app/component/forder-list-header/forder-list-header.component.spec.ts (700 bytes)
CREATE src/app/component/forder-list-header/forder-list-header.component.ts (316 bytes)
UPDATE src/app/app.module.ts (3872 bytes)

参考サイト

angular - Invalid rule result: Instance of class Promise - Stack Overflow

Invalid rule result: Instance of class Promise. ng add @angular/pwa · Issue #15290 · angular/angular-cli · GitHub

Node.jsとnpmをアップデートする方法 | Rriver

GitHub - tj/n: Node version management

【C++】[VSCode]Code Runnerで標準入力(cin)のプログラムを実行する

はじめに

VSCode上でC, C++, Java..etc を実行できるようにする機能拡張であるCode Runnerを使ってC++を書いていたのですが、キーボードから入力した値を使用する標準入力のプログラムを書いているときに値の入力ができてなくて困ることがありました。

環境

  • 使用エディタ: Visual Studio Code v1.40.2
  • Code Runner v0.9.15
  • macOS Mojave v10.14.6

Code Runnerだと標準入力ができない?

Code Runnerはプログラムの実行結果をデフォルト設定だとReadOnlyである「出力」欄に表示するため、キーボードによる標準入力がそのままだと実行できません。

  • 標準入力のプログラム(C++)
// 標準入力で入力した値の合計結果を表示するプログラム
#include <iostream>

using namespace std;

int main()
{
    int x, y;

    cout << "xとyを加算します。\n";

    cout << "xとyの値:";

    cin >> x >> y; // 標準入力でxとyに値を代入する

    cout << "x+y:" << x + y << "。\n"; // xとyの合計結果を表示する
}

ためしに上記のC++の標準入力のプログラムをCode Runnerで実行してみましたが、「出力欄」が読み取り専用のため、標準入力をすることができません。

f:id:l08084:20191209183611p:plain
標準入力ができない

Code Runnerの出力をターミナルに切り替える

Code Runnerだと標準入力ができない!という上記の問題ですが、設定を変更してCode Runnerの結果を「出力」欄ではなくVSCodeのターミナルに出力するように設定すれば解決できます。

設定方法

その設定方法ですが、まずVSCodeのメニューから [Code] > [基本設定] > [設定] の順でクリックしてVSCodeの設定画面を開きます。

続いて開いた設定画面の検索欄にrunInTerminalというワードを入力します。

そして、code-runner.runInTerminalの設定をON(true)にしてVSCodeを再起動すると設定完了です。

f:id:l08084:20191209185046p:plain
code-runner.runInTerminalの設定にチェックを入れる

動作確認

上記の設定をした後に、再度プログラムを実行すると標準入力ができるようになっていることがわかります。

f:id:l08084:20191209203729p:plain
標準入力に成功

参考サイト

CodeRunnerの出力をターミナルに出す方法[VSCode]|てくてくぷれいす

Code Runner - Visual Studio Marketplace

ng updateでAngularをv7 -> v8にアップグレードする

はじめに

趣味プロ中にAngular v8以上じゃないと使えない構文がでてきたので、Angularのバージョンを7から8にアップグレードすることにした。

Angular CLIで作成したプロジェクトなので、ng updateコマンドでアップグレードを実施することができる。

環境

アップグレード前のAngularプロジェクトのバージョン情報

$ ng version

Angular CLI: 7.3.9
Node: 8.11.3
OS: darwin x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.9
@angular-devkit/build-angular     0.13.9
@angular-devkit/build-optimizer   0.13.9
@angular-devkit/build-webpack     0.13.9
@angular-devkit/core              7.3.9
@angular-devkit/schematics        7.3.9
@angular/cdk                      7.3.7
@angular/cli                      7.3.9
@angular/fire                     5.2.3
@angular/material                 7.3.7
@ngtools/webpack                  7.3.9
@schematics/angular               7.3.9
@schematics/update                0.13.9
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.29.0

出典元(公式サイトURL)

angular.jp

アップグレード

公式サイトの説明にしたがってng update @angular/cli @angular/coreコマンドを実行

$ ng update @angular/cli @angular/core

ng updateコマンドを実行した後に、ng versionコマンドを実行することで正常にアップグレードされていることを確認する

$ng version

Angular CLI: 7.3.6
Node: 8.11.3
OS: darwin x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.20
@angular-devkit/build-angular     0.803.20
@angular-devkit/build-optimizer   0.803.20
@angular-devkit/build-webpack     0.803.20
@angular-devkit/core              8.3.20
@angular-devkit/schematics        8.3.20
@angular/cdk                      7.3.7
@angular/cli                      8.3.20
@angular/fire                     5.2.3
@angular/material                 7.3.7
@ngtools/webpack                  8.3.20
@schematics/angular               8.3.20
@schematics/update                0.803.20
rxjs                              6.5.3
typescript                        3.5.3
webpack                           4.39.2

Angularの7から8へのアップグレードが正常に完了していることがわかる

動作確認とエラーの解消

続いて、アップグレードしたAngularプロジェクトをng serve --openコマンドでビルドしてみると、エラーが発生する。

$ ng serve --open
Schema validation failed with the following errors:
  Data path ".builders['app-shell']" should have required property 'class'.
Error: Schema validation failed with the following errors:
  Data path ".builders['app-shell']" should have required property 'class'.
    at MergeMapSubscriber._registry.compile.pipe.operators_1.concatMap.validatorResult [as project] (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/src/workspace/workspace.js:215:42)
    at MergeMapSubscriber._tryNext (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:69:27)
    at MergeMapSubscriber._next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:59:18)
    at MergeMapSubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:67:18)
    at MergeMapSubscriber.notifyNext (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:92:26)
    at InnerSubscriber._next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/InnerSubscriber.js:28:21)
    at InnerSubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:67:18)
    at MapSubscriber._next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/map.js:55:26)
    at MapSubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:67:18)
    at SwitchMapSubscriber.notifyNext (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/switchMap.js:86:26)
    at InnerSubscriber._next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/InnerSubscriber.js:28:21)
    at InnerSubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:67:18)
    at /usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeTo.js:17:28
    at Object.subscribeToResult (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeToResult.js:10:45)
    at SwitchMapSubscriber._innerSub (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/switchMap.js:65:54)
    at SwitchMapSubscriber._next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/switchMap.js:55:14)

上記のエラーだが、下記の手順で修正することができる。

  1. package.jsonを開いて、"@angular-devkit/build-angular"のバージョンを"^0.800.0"から"~0.12.1"にする
  2. node_modules/ディレクトリを配下ごと削除して、npm iコマンドでnpmパッケージをインストールする

上記の手順でエラーを解決してng serve --openコマンドを実行すると下記の別のエラーが発生する。

$ ng serve --open
Schema validation failed with the following errors:
  Data path "" should NOT have additional properties(es5BrowserSupport).

上記のエラーについては下記の手順で解消することができる

  • angular.jsonファイルを開いて、"es5BrowserSupport": trueと書かれている行を削除する

上記の手順を実行すると全てのエラーが解消し、ビルドできるようになる

参考サイト

angular - Ionic problem: [ng]Schema validation failed with the following errors:[ng]Data path".builders['app-shell']"should have required property 'class' - Stack Overflow

angular - Schema validation failed with the following errors: Data path ".builders['app-shell']" should have required property 'class' - Stack Overflow

angular - Data path '''' should NOT have additional properties (es5BrowserSupport) - Stack Overflow

angular - Error: Schema validation failed with the following errors: Data path "" should NOT have additional properties(project) - Stack Overflow

Angular 日本語ドキュメンテーション

【障害メモ】[ionic-v3][Android][input text]ワンタップでキーボードが出てこない・文章の途中にカーソルを合わせることができない

障害内容

Ionic v3のAndroidアプリで、入力フォームを複数回タップしないとソフトキーボードが出てこなかったり、文章の途中に間違いがあってもカーソルをテキストの最後にしか移動できないから、全消ししないと誤った文章を修正できない、といった障害が発生した。

障害を検知したのは、Android 9.0の端末となる。

環境

  • cordova (Cordova CLI) : 8.0.0
  • Ionic Framework : ionic-angular 3.9.5
  • Android 9.0

修正方法

SCSSファイルに下記の記述を追加したら、障害が改修した。詳しくは参考サイト参照のこと

.md {
  .input-cover {
    display: none;
  }
}

参考サイト

[Accessibility - Android] <ion-input> is not acknowledged by Android Talkback · Issue #1049 · ionic-team/ionic-v3 · GitHub

【障害メモ】[cordova-plugin-keyboard][Android]ソフトウェアキーボードが入力フォームを覆い隠してしまう

障害内容

モバイル・タブレット端末のソフトウェアキーボードが、入力フォームの前面に表示されてしまうため、画面の下部にある入力フォームがキーボードに隠されて見えない。Android端末のみで発生

環境

  • cordova (Cordova CLI) : 8.0.0
  • Ionic Framework : ionic-angular 3.9.5
  • cordova-plugin-ionic-keyboard@2.0.5

修正方法

実際に本障害をなおす上で実施した改修

  1. cordova-plugin-ionic-keyboardのバージョンを2.2.0にアップグレードする
  2. アプリを全画面表示にするのをやめる

ライブラリのアップグレードは必要なかったかも.......

アプリを全画面表示にするのをやめる

具体的には、config.xmlから<preference name="Fullscreen" value="true" />を削除してアプリの全画面表示設定を解除したり、cordova-plugin-statusbarでステータスバーのオーバーレイ設定をオンにしている場合は、オフにするなどする必要がある。

ステータスバーのオーバーレイ表示をオフにする

StatusBar.overlaysWebView(false);

アプリの全画面表示をオンにしたままでも、cordova-plugin-ionic-keyboardresizeOnFullScreentrueにする(config.xmlに<preference name="resizeOnFullScreen" value="true" />を追加する)ことでキーボードの本バグを修正できるとのことだったが、自分の場合は、別の障害(ナビゲーションバーが画面の下部を覆い隠す)が発生したりしてうまくいかなかった

参考サイト

https://github.com/ionic-team/cordova-plugin-ionic-keyboard#resizeonfullscreen-for-android-only

https://github.com/apache/cordova-plugin-statusbar#statusbaroverlayswebview

【障害メモ】[cordova-plugin-camera]縦向きに撮影した画像が横向きで表示される

障害内容

cordova-plugin-cameraを使用して、端末の画像ライブラリから画像を選択したり、写真を撮影したりすると、画像の向きが縦から横に変わって表示される。Android端末のみで発生

環境

  • cordova (Cordova CLI) : 8.0.0
  • Ionic Framework : ionic-angular 3.9.5
  • cordova-plugin-camera@4.7.0

修正方法

camera.CameraOptionscorrectOrientationtrueに設定する。

カメラを使用して写真を撮影したり、デバイスの画像ギャラリーから画像を選択するときに呼ぶcamera.getPicture(successCallback, errorCallback, options)メソッドにcorrectOrientationtrueに設定したoptionsを引数として渡してあげると、正しい画像の向きで写真が表示される。

参考サイト

GitHub - apache/cordova-plugin-camera: Apache Cordova Plugin camera

【Git】SourceTreeでブランチ間の差分を表示する

やりたいこと

GitクライアントソフトのSouceTreeを使用して、ブランチ間の差分を表示する

環境

  • macOS Mojave@10.14.6
  • SourceTree@2.4

やり方

f:id:l08084:20191116195419p:plain

比較対象のブランチを選択したあと、右クリックして[現在のファイルとの差分をとる]をクリックすると、現在のブランチと選択しているブランチの差分が表示されます。

f:id:l08084:20191116203553p:plain
差分が表示される

差分のあるファイルの一覧とその差分内容が表示されます