AngularJS 2.0编译ES6 [英] AngularJS 2.0 compile to 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'或更高。
模块AMD 打字稿
编译器选项 -
我可以通过删除绕过它。
这确实最难解决的问题:不指定AMD,什么样的模块格式为 ES6
使用?
问题2:
修改打字稿
编译器选项后,使他们出现如下:
我开始收到有关错误:
错误TS2300:重复标识符无极
有没有人见过这个?我怀疑它做的 AngularJS 2.0快速入门
指定ES-6承诺,它正在全球范围内安装,但一直没能找出如何解决它。
非常感谢你在前进。
好吧,我已经想通了,这是$ P $从编译 AngularJS 2.0
pventing我的问题快速启动到的ECMAScript 6
:
解决方案:
-
由于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
)。
(这感觉就像一个黑客):我走进了 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:
As basarat mentioned,
ES6
does not supportamd
. I did try specifying--module="system"
compiler flag, but that did not work either, still got the error messageError: 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"
- The command
tsd install angular2 es6-promise rx rx-lite
pulls down ES6 promise, as one would expect. The problem is thatTypeScript 1.5.3
includes aTypeScript Definition file
in thebin
calledlib.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
).
(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屋!