Cannot access fs.readFileSync in custom visualization

I am trying to read a file from within a custom visualization in Kibana 6.2.2. I am calling fs.readFileSync but am getting the following error from Kibana at runtime.

Uncaught TypeError: fs.readFileSync is not a function

It looks as if Kibana cannot find the fs library. I thought that fs was standard in node.js and that it would be available once declared via:

import fs from 'fs';
or
var fs = require('fs');

I have tried installing both fs and fs2 explicity via yarn and npm but with no success. I notice other inbuilt Kibana plugins call fs.fileReadSync with the same syntax which makes me think it may not be a node version issue.

Is there something I am missing with dependencies or libraries when writing visualisations? The 'Managing Dependencies' page in the documentation seems very clear and easy to follow but this one really has me stumped.

Any ideas or guidance from those that may have gone down this path before would be very much appreciated!

You can only read from the filesystem from servier-side code. Is it possible you're attempting to do this from client-side code?

1 Like

That is exactly what is happening, I was trying to access the file from client side. There is my facepalm moment right there - as soon as I read your reply it became immediately obvious! Thank you for your response - it has saved me anther day of frustration.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.