AngularJS 2.0编译ES6 [英] AngularJS 2.0 compile to ES6

查看:457
本文介绍了AngularJS 2.0编译ES6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以得到 AngularJS 2.0 5分钟快速入门的在我的工作的IntelliJ IDEA 14.1.4 以下有关此 AngularJS 2.0打字稿的IntelliJ IDEA(或webstorm) - ES6进口语法

不过,这似乎是针对打字稿的汇编的ECMAScript 5

我想看看我是否能获得 AngularJS 2.0打字稿来编译的ECMAScript 6

问题1::当我修改打字稿编译器瞄准 ES6 ..

我开始得到一个打字稿编译器错误:

 错误:TS1204:无法编译模块插入'CommonJS的,AMD,系统或UMD
定位时'ES6'或更高。

模块A​​MD 打字稿编译器选项 -

我可以通过删除绕过它。

这确实最难解决的问题:不指定AMD,什么样的模块格式为 ES6 使用?

问题2:

修改打字稿编译器选项后,使他们出现如下:

我开始收到有关错误:

 错误TS2300:重复标识符无极

有没有人见过这个?我怀疑它做的 AngularJS 2.0快速入门指定ES-6承诺,它正在全球范围内安装,但一直没能找出如何解决它。

非常感谢你在前进。


解决方案

好吧,我已经想通了,这是$ P $从编译 AngularJS 2.0 pventing我的问题快速启动到的ECMAScript 6

解决方案:


  1. 由于basarat提到的, ES6 不支持 AMD 。我也尝试指定 - 模块=系统编译器标志,但没有工作,要么,还是得到了错误讯息

    错误:TS1204:瞄准'ES6'或更高时无法编译模块插入'CommonJS的,AMD,系统或UMD


该解决方法是为指定任何类型的模块。

我的新的打字稿编译器选项:

   -  experimentalDecorators --targetES6

<醇开始=2>

  • 命令 TSD安装angular2 ES6-RX承诺RX-精简版拉下ES6诺言,正如人们所期望。问题是,打字稿1.5.3 包括打字稿定义在 bin文件 名为 lib.es6.d.ts

  • 这包含了承诺的定义,这与已通过 TSD 命令拉下一个冲突。

    我删除了 ES6-承诺从我Angular2项目目录分型文件夹(通过运行创建的 TSD )。

    <醇开始=3>
  • (这感觉就像一个黑客):我走进了 angular2.d.ts 文件并删除以下行:

    ///参考路径= LT;../ ES6-承诺/ ES6-promise.d.ts/&GT;


  • 我不得不删除的原因是 AngularJS 2.0打字稿类型定义在对等层面寻找ES6承诺。因为打字稿编译(至少我使用的版本,打字稿1.5.3 包含ES6承诺的话)和他们发生冲突。

    I can get the AngularJS 2.0 5 Minute Quickstart working in my IntelliJ IDEA 14.1.4 following this Stackoverflow Answer regarding AngularJS 2.0 TypeScript Intellij idea (or webstorm) - ES6 import syntax.

    However, this appears to be targeting compilation of TypeScript to EcmaScript 5.

    I wanted to see if I could get AngularJS 2.0 Typescript to compile to EcmaScript 6.

    Issue 1: When I change the TypeScript compiler to target ES6 ...

    I start getting a TypeScript compiler error:

    Error: TS1204: Cannot compile modules into 'commonjs', 'amd', 'system', or 'umd' 
    when targeting 'ES6' or higher.
    

    I can get around it by removing the --module "amd" TypeScript compiler option.

    This does beg the question: without specifying amd, what sort of module format is ES6 using?

    Issue 2:

    After modifying the TypeScript compiler options so they appear as follows:

    I start getting errors regarding:

    Error TS2300: Duplicate identifier 'Promise'
    

    Has anyone seen this before? I suspect it has something to do with the AngularJS 2.0 Quickstart specifying ES-6 Promise and it being installed globally, but have not been able to figure out how to resolve it.

    Thank you very much in advance.

    解决方案

    Okay I've figured out the issues that was preventing me from compiling the AngularJS 2.0 Quickstart into EcmaScript 6 :

    Solution:

    1. As basarat mentioned, ES6 does not support amd. I did try specifying --module="system" compiler flag, but that did not work either, still got the error message

      Error: TS1204: Cannot compile modules into 'commonjs', 'amd', 'system', or 'umd' when targeting 'ES6' or higher.

    The fix for that is to NOT specify any sort of module.

    My new TypeScript compiler options:

    --experimentalDecorators --target "es6" 
    

    1. The command tsd install angular2 es6-promise rx rx-lite pulls down ES6 promise, as one would expect. The problem is that TypeScript 1.5.3 includes a TypeScript Definition file in the bin called lib.es6.d.ts.

    This contains a definition of Promise, which conflicts with the one that was pulled down via the tsd command.

    I removed the es6-promise directory from my Angular2 project typings folder (the one that was created by running tsd).

    1. (this felt like a hack): I went into the angular2.d.ts file and removed the following line:

      ///reference path=<"../es6-promise/es6-promise.d.ts"/>

    The reason I had to remove this is AngularJS 2.0 TypeScript Type Definition looks for ES6 Promise at a peer level. Since the TypeScript compiler (at least the version I am using, TypeScript 1.5.3 contains the ES6 Promise already) and they conflicted.

    这篇关于AngularJS 2.0编译ES6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆