0

I don't know what's wrong always fs.exists is not a function...

setBannerEvent = feed => {
  var fs = require("fs");
  let file = feed !== null && feed !== undefined ? feed : "";
  fs.exists(process.env.REACT_APP_BANNER_PATH + file, function(exists) {
    if (exists === true) {
      return (
        <img
          src={process.env.REACT_APP_BANNER_PATH + file}
          className="img-avatar avatar-size"
          width="80px"
          height="80px"
          alt={file}
          style={{ paddingBottom: "0px" }}
        />
      );
    } else {
    }
    return console.log("hey");
  });
};
keikai
  • 14,085
  • 9
  • 49
  • 68
JanCarlo
  • 1
  • 2
  • 1
    You can't use fs in create-react-app https://stackoverflow.com/questions/35003961/react-js-require-fs#:~:text=In%20create%2Dreact%2Dapp%20they,another%20solution%20to%20that%20problem. – boosted_duck Mar 05 '20 at 07:02
  • 1
    Yeah `fs` is available in NodeJS but it's not present in React because it will not work in browser. – Oli Mar 05 '20 at 07:07
  • I'll check the file path if it exists using fs.exist method but there is an error. sorry my English not good – JanCarlo Mar 05 '20 at 07:18

0 Answers0