typescript amd模块无法编译

时间:2013-08-30 11:16:56

标签: typescript amd

我在VS2012中使用最新版本创建了一个项目并添加了两个文件

// file x.ts
export class test {}

// file search.ts
import t = module('x');

问题 - 如何解决以下错误:

Error   1   ';' expected.   D:\Code\Search\Search\node_modules\search\search.ts   1 18  search.ts
Error   2   Module cannot be aliased to a non-module type.  D:\Code\Search\Search\node_modules\search\search.ts 1   1   search.ts
Error   3   Unable to resolve module reference 'module'.    D:\Code\Search\Search\node_modules\search\search.ts 1   12  search.ts

csproj包含以下内容:

<TypeScriptCompile Include="node_modules\search\x.ts" />
<TypeScriptCompile Include="node_modules\search\search.ts" />
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />

x.ts编译正常,但search.ts不是

define(["require", "exports"], function(require, exports) {
    var test = (function () {
    function test() {
    }
    return test;
})();
exports.test = test;
});
//# sourceMappingURL=x.js.map

1 个答案:

答案 0 :(得分:3)

如果您使用的是最新版本,我认为您的意思是0.9.1?在这种情况下you can't use the module keyword anymore for import statements of external modules,请改用require

// file search.ts
import t = require('x');

另一个问题可能是由于search.ts无法找到x.ts,如果以上内容无法解决您的问题,请发布您的文件夹结构。

相关问题