web-dev-qa-db-ja.com

Angular2インポートを含むTypeScriptをコンパイルするときにWebstormで警告を受け取る

私はここから例をとりました https://angular.io/guide/quickstart

クイックスタートマニュアルに従ってすべてを行いました。しかし、app.tsのコンパイル中にWebStormコンソールで警告が表示されます。

詳細は次のとおりです。

私はWindows 8.1 x64、Webstorm 11.0.1を使用しています

app.ts

import {bootstrap, Component} from 'angular2/angular2';
@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 3 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);

tsconfig.json

   {
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "sourceRoot": "/"
  },
  "exclude": [
    "node_modules"
  ]
}

tsconfig.jsonファイルをappフォルダーとルートに配置していました。

app.tsは実際にファイルをコンパイルしていますが、何らかの理由で警告が表示されています。

error TS1148: Cannot compile modules unless the '--module' flag is provided.
error TS2307: Cannot find module 'angular2/angular2'.
error TS1205: Decorators are only available when targeting ECMAScript 5 and higher.
error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.

タイピングが含まれています

私のフォルダ構造

enter image description here

編集:

設定でtsconfig.jsonを設定した後、TypeScriptウィンドウからエラーが消えました

enter image description here

Run出力とコードエディターでエラーが発生しました: enter image description here

tsconfig.jsonに問題はありません: enter image description here

更新:

ファイル->設定->言語とフレームワーク-> TypeScriptはtsconfig.jsonへの切り替えを支援しました。次に、以前に手動で有効にしておいたTypeScriptウォッチャーを無効にすることで、次の問題を解決しました:ファイル->設定->ツール->ファイルウォッチャー。これらの設定で、すべてが正常に動作しています。

15
sreginogemoh

Webstormの[ファイル]-> [設定]に移動する必要があります。そして、設定サイドバーで、言語とフレームワーク-> TypeScriptに移動します。

次に、TypeScript設定ページにSet options manuallyまたはUse tsconfig.jsonのラジオボタンオプションがあります。 tsconfigオプションを選択し、変更を適用して閉じます。次に、Webストームは、TypeScriptをコンパイルするときにtsconfigオプションを使用することを知っている必要があります。

38
Marc Harry