2016-02-29 111 views

回答

2

您必須要告訴編譯器,例如在NPM

選項:

-m, --module Specify module code generation: 'commonjs' or 'amd'

例子:

tsc.compile(['test/cases/ship.ts', 'test/cases/fleet.ts'], '-m commonjs -t ES5 --out test/tmp/navy.js');

更多參考:TypeScript compiler

也看看這個視頻:TypeScript Modules Demystified : Internal, AMD with RequireJS, CommonJS with NodeJS

+0

謝謝。在WebStorm的TypeScript設置中有一個寫命令行選項的地方,所以我在那裏寫了「-m commonjs -t ES5」。在它被設置爲「-m amd -t ES5」之前,我看到了它。 – Alon

4

我不是一個WebStorm用戶自己,但我認爲WebStorm指tsconfig.json文件在這種類型的編譯器配置您的打字稿項目的根。

Here's the documentation for the tsconfig.json file.

如果這個文件不存在於你的項目已經存在,創建一個在您的打字稿編譯目錄的根目錄。在這個文件中,你可以告訴編譯器,模塊系統與module參數的使用方法:

{ 
    "compilerOptions": { 
     "module": "commonjs" 
    } 
} 

見上面的鏈接爲tsconfig.json文件的更完整的例子。

+0

謝謝,這很有幫助。我採取了另一個人的建議,但我投了票。 – Alon

相關問題