Reputation: 43
I've created an electron app based on this link (but using recent modules).
I want to create a simple desktop app, I need to open some local files. I know that there is the node fs API for this, but I'm have problems with referencing it correctly.
Here is what I tried:
Based on this queston in Stackoverflow, I tried to import and use fs like this:
///<reference path="../typings/node/node.d.ts"/>
import fs = require('fs');
fs.readFileSync('foo.txt','utf8');
As a result, I got a Module not found: Error: Cannot resolve module 'fs' when I called npm run build
Then I added the following lines to webpack.config.js (I read it somewhere):
node: {
fs: "empty"
},
then npm run build command was OK, but I see the following error at runtime in electron's developer tool: TypeError: fs.readFileSync is not a function
I'm new to this topic, and I would appreciate if someone could help me how to reference node's fs API correctly.
Upvotes: 4
Views: 4163
Reputation: 14847
You need to set target: 'electron-renderer'
in your Webpack config, if you still have issues after that take a look at https://github.com/chentsulin/electron-react-boilerplate
Upvotes: 3