angular - 角度 7 - 导入 json 文件 - 编译错误
问题描述
angular 7 的一个非常好的特性是对 typescript 3.1 的支持:
https://alligator.io/angular/angular-7/
我在 tsconfig.json 文件中添加了以下 3 行 - 在“compilerOptions”部分下:
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
一切看起来都不错——我可以毫无问题地遍历我的 json 文件。
但由于某种原因,我的 IDE 中出现“TS2307:找不到模块”错误:
我尝试将导入语法更改为此处的建议: Importing json file in TypeScript
但没有成功。
有任何想法吗?
编辑:我使用Webstorm作为 IDE。
解决方案
所以你没有提到你正在使用的 IDE,但我使用 VSCode,帮助我添加的是:
"angularCompilerOptions": {
"annotateForClosureCompiler": false
}
到src/tsconfig.app.json
我不再有导入问题,我的 IDE 带有.json
文件。专业提示,尝试:
import { default as awsData } from `....`
这将摆脱作为default
属性添加到返回的 JSON 对象中的导入。
推荐阅读
- swift - 如何知道快照视图更高效?
- ansible - 如何修复“无法匹配提供的主机模式,忽略:bigip”错误,适用于 Ansible,而不是 Tower
- python - 关于“TypeError:需要一个类似字节的对象,而不是'str'”
- php - 如何通过 jquery 将“multipart/form-data”(图片、pdf 等)保存到 mysql 数据库 mediumblob?
- angular - 使用带有 ActionBar 后退按钮的 NativeScript + Angular 递归导航到具有历史记录的相同组件?
- c - 为什么执行这个基本程序会出错?
- python - 给定一个已经创建的python对象,有没有办法通过检查找出构造的实际参数?
- here-api - 清除站点数据中断映射 - IndexedDB 未处理关闭的连接
- angular - 如何为以 Azure AD 作为身份提供者的 Angular 7.x 应用程序实施基于 SAML 的身份验证?
- windows - 如何将批处理文件的结果输出到与输入文件同名的文件夹中?