How to use FS module inside Electron.Atom\WebPack application?


Hi guys. I need write some data in the file, using FS module (fs.writeFile). My stack is webpack + react + redux + electron.

The first problem was: Cannot resolve module ‘fs’.
I tried to use
target: “node”,

node: {
global: true,
fs: “empty”,

resolve: {
root: path.join(__dirname),
fallback: path.join(__dirname, ‘node_modules’),
modulesDirectories: [‘node_modules’],
extensions: [’’, ‘.json’, ‘.js’, ‘.jsx’, ‘.scss’, ‘.png’, ‘.jpg’, ‘.jpeg’, ‘.gif’]

After several attempts, the problem is resolved ( node: {fs: “empty”} ). But then there was a second problem: screenshot.

//In method componentDidMount (React)
console.log('fs', fs);
console.log('typeOf', typeof fs.writeFile);

//By clicking on the button
console.log(typeof fs.writeFile);

You can see, that fs is empty object, and method writeFile no exists. I tried to change the webpack’s configuration.
const path = require(‘path’);
const fs = require(‘fs’);
const webpack = require(“webpack”);

In this case fs is not empty.

How to solve this problem? Any ideas?


I have the same issue :confused: Any updates?


Same pbm for me !
Hope someone have a solution


Hi guys. There is a solution:

var {remote} = require('electron');
var electronFs = remote.require('fs');



    <script src="js/electron.js"></script>


electron = require('electron')
fs = electron.remote.require('fs')

fs.writeFile(path, content, (err) => {
      if (err) throw err;
      console.log('It\'s saved!');

you should customize “path” and “content”.
path is file path and content is a writing.
i think that my code isn’t good code. because i started “Electron” before 1week.


I have the same issue :confused: Any updates?