【问题标题】:Getting Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'除非“--module”标志是“amd”或“system”,否则无法使用选项“outFile”编译模块
【发布时间】:2019-12-30 01:51:01
【问题描述】:

我正在 app.ts 文件中编写导入语句 import { PI } from './math/circle' 并在 circle.ts 文件中有一个常量 export const PI = 3.14 但通过执行运行程序tsc app.ts --outFile app.js 一直显示这个错误。

错误 TS6131:无法使用选项“outFile”编译模块,除非“--module”标志为“amd”或“system”。 1 导出常数 PI = 3.14

但根据docs 我正确导入。我也尝试将 "module": "commonjs" 更改为 "module": "amd"/"system" 然后重新加载 VSCode 窗口,但没有运气。我哪里错了?

tsconfig.json

{
  "compilerOptions": {    
    "target": "es5",                         
    "module": "amd",                    
    "strict": true,                          
    "noImplicitAny": true,                
    "strictNullChecks": true,              
    "strictPropertyInitialization": false
  },
  "exclude": [
    "node_modules"
  ]
}

PS:打字稿版本 3.5.3

【问题讨论】:

    标签: typescript


    【解决方案1】:

    如果您希望您的tsconfig.json 被考虑在内,您必须在没有输入文件的情况下调用 tsc 命令,更多详细信息here。 运行 tsc app.ts --outFile app.js 您将跳过您的 tsconfig.json,因此您必须手动指定模块系统,因此运行 tsc app.ts --outFile app.js --module amd 应该可以解决问题。

    上面提到的另一个选项就是运行tsc --outFile app.js

    【讨论】:

      【解决方案2】:

      您应该使用webpack 之类的工具将多个打字稿文件捆绑到一个 javascript 文件中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-21
        • 2016-05-14
        • 1970-01-01
        • 2013-08-27
        相关资源
        最近更新 更多