我需要在文件中写入一些数据,使用 FS 模块 (fs.writeFile).我的堆栈是 webpack + react + redux + electron.
I need write some data in the file, using FS module (fs.writeFile). My stack is webpack + react + redux + electron.
第一个问题是:无法解析模块fs".我尝试使用
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']
},
经过多次尝试,问题得到解决(node: {fs: "empty"}).但随后出现了第二个问题:截图.
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);
可以看到,fs是空对象,不存在writeFile方法.我试图改变 webpack 的配置.
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);
在这种情况下 fs 不为空.
In this case fs is not empty.
如何解决这个问题?有什么想法吗?
How to solve this problem? Any ideas?
问题解决了.
需要在电子应用程序中使用(添加捆绑包的地方):
Need use in electron app (where you add the bundle):
var remote = require('electron').remote;
var electronFs = remote.require('fs');
var electronDialog = remote.dialog;
这篇关于如何在 Electron.AtomWebPack 应用程序中使用 FS 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
discord.js v12:我如何等待 DM 频道中的消息?discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
如何让我的机器人提及发出该机器人命令的人how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
如何修复必须使用导入来加载 ES 模块 discord.jsHow to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
如何列出来自特定服务器的所有成员?How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot:修复“找不到 FFMPEG"Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
使用 discord.js 加入 discord 服务器时的欢迎消息Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)