如何管道要求?

How to pipe on require?

我正在尝试从 json 文件和管道中读取。

return of(
    require(`../../../assets/mydata.json`).pipe(
      map((listItems: ListItem[]) => {
        return { listItems: listItems };
      })
    )
  );

但是我收到这个错误

ERROR TypeError: webpack_require(...).pipe is not a function

这可能吗?或者有其他选择吗?

你只需要移动一个括号:

return of(require(`../../../assets/mydata.json`))
  .pipe(
    map((listItems: ListItem[]) => {
      return { listItems: listItems };
    })
  );