【发布时间】:2019-07-30 20:04:33
【问题描述】:
我正在尝试从 json 文件和管道中读取数据。
return of(
require(`../../../assets/mydata.json`).pipe(
map((listItems: ListItem[]) => {
return { listItems: listItems };
})
)
);
但是我收到了这个错误
ERROR TypeError: webpack_require(...).pipe 不是函数
这可能吗?或者有其他选择吗?
【问题讨论】:
-
很难说你在做什么。这是在节点中还是在浏览器中?如果在浏览器中,可以使用
import('your-file.json').then(json => ...);。如果在节点中,要求语句被阻塞:const json = require('your-file.json'); console.log(json);
标签: javascript typescript webpack pipe require