Search code examples
typescriptamd

typescript amd modules can't be compiled


I've created a project in VS2012 using the latest version and added two files

// file x.ts
export class test {}

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

The question - how to fix the following errors:

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 contains the following:

<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 is compiled fine, but search.ts is not

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

Solution

  • If you're using the latest version, I assume you mean 0.9.1? In that case you can't use the module keyword anymore for import statements of external modules, use require instead.

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

    Another problem could be caused by the fact search.ts can't find x.ts, if the above does not fix your issue, please post your folder structure.