angular - TypeScript [警告] 转换为 CommonJS,考虑设置模块 : "system" in typescript Options

标签 angular typescript

使用 Angular 2,我在 Chrome 控制台中收到警告:

TypeScript [Warning] transpiling to CommonJS, consider setting module: "system" in typescriptOptions to transpile directly to System.register format

我已经彻底搜索了网络,但找不到有关此问题的解决方案或文章。

我确实找到了this网站,提到使用:

--allowSyntheticDefaultImports  (boolean)   

作为

module === "system"

我添加到我的 tsconfig.json 文件中:

{
  "compilerOptions": {
    "target": "es5",
    //"module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noEmitHelpers": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "allowSyntheticDefaultImports": true,
    "module": "system"
  }
}

但这并没有帮助。

有什么建议吗?

最佳答案

您可以通过设置 tsconfig.json 选项的 compilerOptions 来将 module 设置为 system 选项。

tsconfig.json

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "module": "system",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true
    }
}

查找tsconfig.json docs here

您还可以通过命令行执行相同的操作,方法是在命令参数中添加 --module system

关于angular - TypeScript [警告] 转换为 CommonJS,考虑设置模块 : "system" in typescript Options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42392288/

相关文章:

reactjs - 无法解析源映射...错误 : ENOENT: no such file or directory

angular - 在 Angular 7 中,当使用 Observable 时,页面会在没有请求的情况下刷新

forms - Angular 5 - 禁用单选按钮

angularjs - 哪些是 angular2 的好的开源数据网格?

javascript - RxJs:http.get 正在获取一个数组,但我希望订阅者获取单个元素

javascript - 带有 vue-class-component : next function does not accept callback option 的 Vue 路由器

javascript - Angular 4 - 如果 ngModel 不为空则添加类

android - 无法编辑输入,除了 ionic 列表的第一个

angular - flatMap, flat, flatten 在类型 any[] 上不存在

typescript - 无法在 typescript 中初始化geofire对象