Search code examples
javascripttypescriptwebpackpiperequire

How to pipe on require?


I am trying to read from a json file and pipe.

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

But I am getting this error

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

Is this possible? Or is there an alternative?


Solution

  • You just need to move a parenthesis:

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