Search code examples
vue.jselectronvue-componentfs

vuejs with electron, can't use fs


I'm using Vue with it's Electron plugin and I want to use fs to read directories, but it gives me this error. What could be the problem?

TypeError: Object(...) is not a function

import Vue from 'vue';
import Component from 'vue-class-component';
import { readdir } from 'fs';

@Component
export default class Directory {
  mounted() {
    readdir('C:/', (err, files) => {
      if (err) console.log(err);
      console.log(files)
    })
  }
}

Solution

  • I only worked with Angular+Electron combo, but with that I used electron's main process to do file manipulation stuff.

    Further read: https://www.electronjs.org/docs/api/ipc-main

    In the main process, you can access "fs" easily like you would in node.

    I don't know if this is the case with Vue, but maybe this helps.