Epubjs compatibility with ionic 4?

#1

Hello, i tried to implement epubjs in a ionic 4 project but when i try to initialize a book, my web page blank, does anyone have a solution?

#2

now i can initialize a book like that

import { Component, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
import  Epub  from 'epubjs';
import {Subject} from 'rxjs-compat';
import {} from 'fs'; 

export class Book {
  label: string;
  file: string;
}

@Component({
  selector: 'app-home',
  templateUrl: './home.page.html',
  styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
  
  books: {}[];
  constructor() {

    this.books = [];
    const epubfolder = '../../assets/books/';
    let fs;
  fs.readdir(epubfolder, (err, files) => {
  files.forEach(file => {
  (epubfolder + file);
    let stock = new Book();
    stock.label = file;
    stock.file = epubfolder + file + "/";
    this.books.push(stock);
    });
  })
  }

  ngOnInit() {
  }

}

but go this error

core.js:14597 ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘readdir’ of undefined
TypeError: Cannot read property ‘readdir’ of undefined
at new HomePage (home.page.ts:25)
at createClass (core.js:20714)
at createDirectiveInstance (core.js:20595)
at createViewNodes (core.js:21821)
at createRootView (core.js:21735)
at callWithDebugContext (core.js:22767)
at Object.debugCreateRootView [as createRootView] (core.js:22253)
at ComponentFactory_.push…/node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:20074)
at ComponentFactoryBoundToModule.push…/node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create (core.js:9717)
at ViewContainerRef_.push…/node_modules/@angular/core/fesm5/core.js.ViewContainerRef_.createComponent (core.js:20185)
at resolvePromise (zone.js:831)
at resolvePromise (zone.js:788)
at zone.js:892
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:16147)
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)

#3

hello,
you have declared inside your constructor
let fs;
In the next line you want use fs, but fs is undefined. Before you can use it you need to fill fs with something fs = whatever;

Best regrads, anna-liebt