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

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

问题描述

我可以获得



我开始获得一个 TypeScript 编译器错误:

 错误:TS1204:当定位ES6或更高版本时,无法将模块编译为commonjs,amd,system或umd

我可以通过删除 - 模块amd / code> TypeScript 编译器选项。



这确实提出了一个问题:没有指定amd,什么样的模块格式是 ES6 使用?



问题2:



修改 编译器选项,它们显示如下:





我开始收到错误:

 错误TS2300:重复标识符'Promise'


$ b有没有人看过这个?我怀疑它与指定ES-6 Promise的 AngularJS 2.0 Quickstart 有关,它在全球安装,但无法弄清楚如何解决它。



非常感谢您提前。

解决方案

我想出了阻止我编译 AngularJS 2.0 快速入门到 EcmaScript 6 的问题:



解决方案:


  1. 作为basarat提到的 ES6 不支持 amd 。我确实尝试指定 - module =system编译器标志,但是没有工作,仍然收到错误消息



    错误:TS1204:当定位ES6或更高版本时,无法将模块编译为commonjs,amd,system或umd。




    1. 解决方法是 指定任何类型的模块。



      我的新 TypeScript 编译器选项:

         -  experimentalDecorators --targetes6




      1. 命令 tsd install angular2 es6-promise rx rx-lite 按照预期的方式拉下ES6的承诺。问题是 TypeScript 1.5.3 bin 中包含一个 TypeScript定义文件 code>调用 lib.es6.d.ts

      这包含Promise的定义,它与通过 tsd 命令。



      我从Angular2项目中删除了 es6-promise 目录打字文件夹(通过运行 tsd 创建的文件夹)。


      1. (这感觉像一个黑客):我进入了 angular2。 d.ts 文件,并删除以下行:



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


      原因我不得不删除这是 AngularJS 2.0 TypeScript类型定义在同级级别查找ES6 Promise。由于 TypeScript编译器(至少我使用的版本 TypeScript 1.5.3 已经包含ES6 Promise)和他们冲突。


      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天全站免登陆