除非提供“--module”标志,否则无法编译模块

Cannot compile modules unless the '--module' flag is provided

我有打字稿 1.5.3 和 visual studio 2015。

我在打字稿中使用了外部模块,但由于以下错误而无法构建: "Build: Cannot compile modules unless the '--module' flag is provided."

打字稿设置:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Any CPU'">
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
<TypeScriptRemoveComments>False</TypeScriptRemoveComments>
<TypeScriptOutFile />
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />

模块:

export class Functions {
errorHelper(xhr: any, errorType: any, exception?: any) {
    var errorMessage = exception || xhr.statusText;
    alert(`Account lookup failed. ${errorMessage}`);
}

getParameterByName(name: string) {
    name = name.replace(/[\[]/, '\[').replace(/[\]]/, '\]');
    var regex = new RegExp(`[\?&]${name}=([^&#]*)`);
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}

看看 Whosebug 上的 。 VS2015 RTM 中存在错误。您必须编辑 csproj 文件才能解决该问题。

To fix:

  1. Right-click the project, unload it, then right click again and edit it.
  2. Search for <TypeScriptModuleKind>, and then locate the parent element, which should be called <PropertyGroup>.
  3. Look for the text "Any CPU" in the Condition attribute value, change it to "AnyCPU" -- i.e. remove the space.
  4. Search again and repeat the change in case you have TypeScript settings for other build conditions.