【问题标题】:Cannot compile modules unless the '--module' flag is provided [duplicate]除非提供“--module”标志,否则无法编译模块[重复]
【发布时间】:2015-08-28 14:29:57
【问题描述】:

我有 typescript 1.5.3 和 Visual Studio 2015。

我在我的打字稿中使用了外部模块,但由于以下错误,它不会构建: “构建:除非提供 '--module' 标志,否则无法编译模块。”

打字稿设置:

<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, ' '));
}

【问题讨论】:

    标签: typescript visual-studio-2015 typescript1.5


    【解决方案1】:

    查看 Stackoverflow 上的 post。 VS2015 RTM 中有一个错误。您必须编辑 csproj 文件才能解决该问题。

    修复:

    1. 右键单击项目,将其卸载,然后再次右键单击并进行编辑。
    2. 搜索&lt;TypeScriptModuleKind&gt;,然后找到父元素,应该叫&lt;PropertyGroup&gt;
    3. Condition 属性值中查找文本“Any CPU”,将其更改为“AnyCPU”——即删除空格。
    4. 再次搜索并重复更改,以防您有其他构建条件的 TypeScript 设置。

    【讨论】:

    • 那行得通。你太棒了!谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 2016-05-14
    • 1970-01-01
    • 2013-08-27
    • 2016-03-03
    • 2019-12-30
    相关资源
    最近更新 更多