【问题标题】:cannot compile external modules unless the '--module' flag is provided除非提供了“--module”标志,否则无法编译外部模块
【发布时间】:2015-05-20 08:27:31
【问题描述】:

在 angularjs2 和 Typescript 1.5beta 中使用 Visual Studio 代码时出现问题。

错误:(3, 1) TS1148:除非提供“--module”标志,否则无法编译外部模块。
错误:(6, 1) TS1205:装饰器仅在面向 ECMAScript 5 及更高版本时可用。

我可以使用命令行编译器运行相同的代码 tsc -t es5 -m commonjs app.ts。同样的问题也出现在 webstorm 10.0.2 上。

【问题讨论】:

    标签: angular visual-studio-code typescript1.5


    【解决方案1】:

    这就是我在 Webstorm/IntelliJ 中解决它的方法

    文件>设置>语言和框架> TypeScript

    命令行选项:

    -m amd -t ES5

    【讨论】:

    • 对 Ecmascript 6 使用 -m amd -t ES6
    【解决方案2】:

    自己在 Visual Studio 代码上解决了这个问题。 步骤:

    1)tsd 初始化

    2)tsd 查询角度 --action install --save

    3)创建 tsconfig.json 。配置文件看起来像这样

    { "compilerOptions": { "target": "ES5", "module": "commonjs", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false } }

    但仍然不知道如何让它在 webstorm 上运行

    【讨论】:

    • 有关tsconfig.json的更多信息,请参阅github.com/Microsoft/TypeScript/wiki/tsconfig.json
    • 在 webstorm 中你可以在 Preferences -> Languages & Frameworks -> TypeScript 中添加命令行选项--module commonjs
    • 在添加命令行选项如“--module commonjs”时显示错误无法启动编译器进程
    • 我也遇到了错误“无法启动编译器进程”......但在删除任何文件观察程序并重新启动 WebStorm 后它消失了......我还在命令行选项中添加了-t es5.. .
    • 在 WebStorm 11(目前处于早期访问预览版)中,您可以让 WebStorm 使用 tsconfig.json,因此不再需要手动设置命令行选项。
    【解决方案3】:

    我在使用 Visual Studio Code 和 ng2-meteor 时遇到了同样的错误。

    不确定是否需要使用第二个 tsd 命令创建的 angular.d.ts,但这个 tsconfig.json 似乎可以排序:

    {
      "compilerOptions": {
        "module": "system",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 2016-05-14
      • 2016-03-03
      • 2019-12-30
      相关资源
      最近更新 更多