简体   繁体   中英

Unhandled Rejection (TypeError): fs.existsSync is not a function

I use epub-gen in reactjs .

Unhandled Rejection (TypeError): fs.existsSync is not a function

I tested import * as fs from "fs" instead of var fs = require("fs") .

epub-gen/lib/index.js here .

// Generated by CoffeeScript 2.3.2
(function() {
  var fs = require("fs");
...
  EPub = class EPub {
..
      if (!fs.existsSync(this.options.tempDir)) {
        fs.mkdirSync(this.options.tempDir);
      }
    ..

I assume that you want to generate file using web application. It's impossible to use FileSystem inside react web application because browser doesn't have access to file system.

To do that you should create backend in node and use this piece of code in your node application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM