1

I have a problem getting fs.readFile to return a css file. I've already read in this SO post that EISDIR error occurs when you try to open a file, but the path given is a directory. But I've checked several times and the console.log inside the getCss function is logging the right path with the correct filename and .css extension. What's the issue? Thanks in advance!

// Path to MUI css
muiCssFile = path.join(muiDistFolder, 'css', 'mui.css'),  


// Read css files
function getCss(callback) {
  console.log('MUI CSS file path in getCss() :: ', muiCssFile);
  // Code fails here.... 
  fs.readFile(muiCssFile, 'utf8', function (err, css) {
    if (err) {
      return callback(err);
    }
    fs.readFile(styleFile, function (error, customCss) {
      if (error) return callback(error);
      callback(null, css + customCss);
    });
  });

}

Community
  • 1
  • 1
mikeym
  • 5,705
  • 8
  • 42
  • 62
  • On which line are you getting the error, you have two calls to `readFile` – 11thdimension May 16 '17 at 21:00
  • The very first one. – mikeym May 16 '17 at 21:01
  • 1
    Try navigating to the path that is printed in the console. If that works, then try changing the name of the file. This will probably give some clue. – 11thdimension May 16 '17 at 21:12
  • Ok. This was an oversight on my part. Turns out it was actually the second fs.readFile that was throwing the error. When I checked the path variable it was indeed missing it's extension so readFile thought it was a folder! Lesson learned. Thanks for the help debugging it! – mikeym May 17 '17 at 20:22

1 Answers1

7

Ok, just for anyone stumbling across this error I thought it would help to provide a short answer to my question. The error is most likely caused by one or more of the paths you are trying to use fs.readFile on ending on a directory path and NOT a file.

In my specific case above, the error was actually occurring on the second fs.readFile call so be sure to check ALL paths first and ensure that they do in fact lead to files to uncover the problem path. Hope that helps someone save some time getting past this error.

mikeym
  • 5,705
  • 8
  • 42
  • 62