【问题标题】:angular 7 - importing a json file - compilation error角度 7 - 导入 json 文件 - 编译错误
【发布时间】:2019-05-23 00:05:37
【问题描述】:

angular 7 的一个非常好的特性是对 typescript 3.1 的支持:

https://alligator.io/angular/angular-7/

我已将以下 3 行添加到 tsconfig.json 文件 - 在“compilerOptions”部分下:

"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true

一切看起来都不错——我可以毫无问题地遍历我的 json 文件。

但由于某种原因,我的 IDE 中出现“TS2307:找不到模块”错误:

我尝试将导入语法更改为此处的建议: Importing json file in TypeScript

但没有成功。

有什么想法吗?

编辑:我使用Webstorm 作为 IDE。

【问题讨论】:

  • 你解决过这个问题吗?我正在处理同样的事情。
  • 仍在等待答复。

标签: angular typescript compiler-errors


【解决方案1】:

所以你没有提到你正在使用的 IDE,但我使用的是 VSCode,帮助我添加的是:

"angularCompilerOptions": {
"annotateForClosureCompiler": false  
}

src/tsconfig.app.json

我不再有导入问题,我的 IDE 使用 .json 文件。 专业提示,请尝试:

import { default as awsData } from `....`

这将消除在返回的 JSON 对象中添加为 default 属性的导入。

【讨论】:

【解决方案2】:

设置"resolveJsonModule": true 后重新启动IDE 应该可以工作。

【讨论】:

    猜你喜欢
    • 2016-01-02
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多