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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…