Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  107] [ 6]  / answers: 1 / hits: 41954  / 8 Years ago, thu, june 23, 2016, 12:00:00

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(fs);
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);
console.log(fs);


In this case fs is not empty.



How to solve this problem? Any ideas?


More From » node.js

 Answers
117

Problem is solved.



Need use in electron app (where you add the bundle):



var remote = require('electron').remote;
var electronFs = remote.require('fs');
var electronDialog = remote.dialog;

[#61669] Tuesday, June 21, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yaquelina

Total Points: 517
Total Questions: 101
Total Answers: 96

Location: Egypt
Member since Tue, Jul 6, 2021
3 Years ago
yaquelina questions
;