I have followed the instructions here and have setup webpack, but still couldn't use fs module to read the file.
Note: I am aware of open() function provided by k6 to read file but i want to check if the file exists before reading, because open() function throws go runtime error if file does not exist.
Using a native node module like
fs
isn't supported.What you should probably use is a function wrapper around
open
to check if a file exists:It is important also to note that open is only supported in the init context so you can't use it inside the default function. So if this is some integral part of your test you should probably rethink how it's done.