【问题标题】:Getting warnings in Webstorm when compiling Typescript that contained Angular2 imports编译包含 Angular2 导入的 Typescript 时在 Webstorm 中收到警告
【发布时间】:2015-11-27 08:57:08
【问题描述】:

我只是从这里举了一个例子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.

我已经输入了输入内容

我的文件夹结构

编辑:

我在设置中设置tsconfig.json 后,错误从Typescript 窗口中消失了

但在Run 输出和代码编辑器中出现错误:

tsconfig.json 没有问题:

更新:

文件 -> 设置 -> 语言和框架 -> TypeScript 帮助切换到tsconfig.json。然后我通过禁用之前手动启用的 Typescript 观察程序解决了下一个问题:文件 -> 设置 -> 工具 -> 文件观察程序。现在有了这些设置,一切正常。

【问题讨论】:

  • 我不确定这个issue 是否与您的问题有关,但值得一读。
  • 我只是想补充一点,即使我的 tsconfig 中确实有正确的设置并且 WS 指向该配置文件,我最近也得到了这个。出于某种原因,我必须重新启动 WS,然后一切都恢复正常。

标签: webstorm angular typescript1.6


【解决方案1】:

您需要进入 Webstorm 中的文件 -> 设置。然后在设置侧边栏上转到语言和框架-> TypeScript。

然后在 TypeScript 设置页面中,Set options manuallyUse tsconfig.json 有一个单选按钮选项。选择 tsconfig 选项,然后应用更改并关闭。那么 webstorm 应该知道在编译 TypeScript 时使用 tsconfig 选项。

【讨论】:

  • 它现在说:发现tsconfig.json 但我有这样的文件,它没有使用它。另外,我刚刚添加了 secton "exclude": [ "node_modules" ],但 webstorm 试图疯狂地构建 node_modules
  • 您是如何在 tsconfig 中构建 excludes 属性的?它是compilerOptions 之后的属性还是设置为compilerOptions 内的属性
  • 我刚刚重启了 Webstorm。 TypeScript compiler 控制台窗口中的错误消失了。但是:Run 输出窗口中仍会出现相同的警告,我在app.ts 窗口中突出显示了相同的错误。
  • 我觉得我的tsconfig.json 不错。刚刚更新了上面的。 Webstrom 说 - No Problems Found 所以这个文件很好。
  • @MarcHarry,添加了我安装的 typescript 2.0+ 编译器,而不是捆绑了 WebStorm 的编译器(我有 1.8.1),效果很好。在 Settings -&gt; Languages &amp; Frameworks -&gt; TypeScript compiler 部分中,将编译器版本更改为所需的打字稿库。这解决了我的问题。
猜你喜欢
  • 2020-07-10
  • 2017-04-10
  • 1970-01-01
  • 1970-01-01
  • 2019-11-12
  • 1970-01-01
  • 1970-01-01
  • 2019-11-04
  • 1970-01-01
相关资源
最近更新 更多