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);
});
});
}
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);
});
});
}
Share Improve this question edited May 23, 2017 at 12:10 CommunityBot 11 silver badge asked May 16, 2017 at 20:56 mikeymmikeym 6,35110 gold badges48 silver badges79 bronze badges 4-
On which line are you getting the error, you have two calls to
readFile
– 11thdimension Commented May 16, 2017 at 21:00 - The very first one. – mikeym Commented May 16, 2017 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 Commented May 16, 2017 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 Commented May 17, 2017 at 20:22
1 Answer
Reset to default 9Ok, 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.