web-dev-qa-db-ja.com

Angular CLIでピア依存関係のインストールを処理するにはどうすればよいですか?

Angular CLIとNPMを更新しようとすると、ほぼ無限のエラーサイクルに陥りました。更新するたびに、ピアの依存関係をインストールするように指示するWARNメッセージが表示されます(以下を参照)が、依存関係をインストールするたびに、より多くのWARNメッセージが表示されます。この状況を処理するより良い方法がありますか、それとも真剣に時間がかかりますか?

npm WARN @angular/[email protected] requires a peer of @angular/[email protected] 
but none is installed. You must install peer dependencies yourself.
npm WARN @angular/[email protected] requires a peer of TypeScript@>=2.4.2 
<2.6 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of 
@angular/core@^4.0.3 but none is installed. You must install peer 
dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of 
@angular/common@^4.0.3 but none is installed. You must install peer 
dependencies yourself.
npm WARN @ng-bootstrap/[email protected] requires a peer of 
@angular/forms@^4.0.3 but none is installed. You must install peer 
dependencies yourself.
npm WARN @schematics/[email protected] requires a peer of @angular-
devkit/[email protected] but none is installed. You must install peer dependencies 
yourself.
npm WARN @schematics/[email protected] requires a peer of @angular-
devkit/[email protected] but none is installed. You must install peer 
dependencies yourself.
npm WARN @schematics/[email protected] requires a peer of @angular-
devkit/[email protected] but none is installed. You must install peer dependencies 
yourself.
npm WARN [email protected] requires a peer of 
@angular/core@^4.0.1 but none is installed. You must install peer 
dependencies yourself.
npm WARN [email protected] requires a peer of 
@angular/common@^4.0.1 but none is installed. You must install peer 
dependencies yourself.
npm WARN [email protected] requires a peer of @angular/platform-
browser@^4.0.0 but none is installed. You must install peer dependencies 
yourself.
npm WARN [email protected] requires a peer of 
@angular/animations@^4.0.1 but none is installed. You must install peer 
dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] - 3 but none 
is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of popper.js@^1.12.3 but 
none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^2.4.7 || ^4.0.0 
but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^2.4.0 || 
^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/common@^2.4.0 || 
^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of TypeScript@>=2.4.2 <2.6 but none 
is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] 
(node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for 
[email protected]: wanted {"os":"darwin","Arch":"any"} (current: 
{"os":"win32","Arch":"x64"})

私は何か間違ったことをしなければならないことは知っていますが、Angularは初めてです。

52
tommy

多くの場合、ピアの依存関係の警告は無視できます。アクションを実行する必要があるのは、ピアの依存関係が完全に欠落している場合、またはピアの依存関係のバージョンがインストールしたバージョンよりも高い場合のみです。

この警告を例として見てみましょう。

npm WARN @ angular/animations @ 5.2.1には@ angular/core @ 5.2.1のピアが必要ですが、何もインストールされていません。自分でピアの依存関係をインストールする必要があります。

Angularでは、使用しているバージョンがすべてのパッケージで一貫している必要があります。互換性のないバージョンがある場合は、package.jsonのバージョンを変更し、npm installを実行して、すべてが同期されるようにします。私はAngularのバージョンを最新バージョンに保つ傾向がありますが、必要なAngularのバージョン(ほとんどの場合はそうではないかもしれません)に対してバージョンが一貫していることを確認する必要があります最近)。

このような状況では:

npm WARN [email protected]には@ angular/core @ ^ 2.4.0のピアが必要です|| ^ 4.0.0がインストールされていません。自分でピアの依存関係をインストールする必要があります。

4.0.0以上のAngularのバージョンを使用している場合、問題は発生しない可能性があります。これについては何もしません。 2.4.0でAngularバージョンを使用している場合は、バージョンをアップする必要があります。 package.jsonを更新し、npm installを実行するか、必要な特定のバージョンに対してnpm installを実行します。このような:

npm install @angular/[email protected] --save

Npm 5.0.0以降を実行している場合は、--saveを省略できます。このバージョンでは、パッケージがpackage.jsonの依存関係セクションに自動的に保存されます。

この状況では:

npm WARNオプションのスキップオプション依存:[email protected](node_modules\fsevents):npm WARN notsupスキップオプション選択依存:[email protected]のサポートされていないプラットフォーム:指名された{"os": "darwin"、 "Arch": "any "}(現在:{" os ":" win32 "、" Arch ":" x64 "})

Windowsを実行しており、fseventにはOSXが必要です。この警告は無視できます。

これがお役に立てば幸いです。Angularを楽しく学んでください。

58
R. Richards

依存関係を更新するときに、Angular cliで--forceフラグを使用すると、ピアの依存関係の警告を無視できます。

ng update @angular/cli @angular/core --force

オプションの完全なリストについては、ドキュメントを確認してください: https://angular.io/cli/update

1