我正在尝试将 .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/