json - 导入json; typescript 错误 : Module has no exported member

标签 json angular

我正在尝试将 .json 文件导入到我的 Angular8 项目中,但由于某种原因,我不断收到“模块没有导出成员”错误。

我试图简化代码,但没有结果。

首先我在 compilerOptions 对象 (tsconfig.json) 中添加了这个 “resolveJsonModule”:是的, “esModuleInterop”:是的,

// assests/example.json
{
  "name": "Spaghetti",
  "desc": "Vegetarische spaghetti bolgnese",
  "rating": 3.7
}

// recipe component
import { example } from '../../../assets/example.json';

  constructor() {
    console.log(example.name);
  }

我不断收到此错误: 模块 '"@angular/recipe-app/src/assets/example"' 没有导出成员 'example'.ts(2305)

我做错了什么?

最佳答案

您必须在示例中使用不带括号的导入。您可以使用以下示例之一:

import example from "../../../assets/example.json";

import * as example from "../../../assets/example.json";

关于json - 导入json; typescript 错误 : Module has no exported member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58324980/

相关文章:

Angular 5 webpack 3 aot

尽管 `runGuardsAndResolvers` 设置为 'always',但 Angular 解析器未更新或重新获取数据?

javascript - Chartjs 中两级圆环图的回调

java - 如何在 Android 中将 ArrayLIst 项转换为 json 对象

java - 以 json 格式返回 solr 响应

python - 批量创建 JSON 配置文件

json - Android 上的 HTTP 错误 500

angular - 如何更改 Angular Material 日期选择器格式

json - 如何将具有未知字段名的 JSON 解码为结构

angular - 在 concat() 字符串中添加新行 - Angular 4