Electron + Angular 2 - Cannot use "fs" module


Trying to build an app with Electron + Angular 2 (and Angular CLI). I actually create the project, install Electron and setup the basic app and all works perfectly, but I lately tried to use the file system Node module in a TS class and once I start Electron it says in devtools:

Uncaught TypeError: fs.existsSync is not a function
    at Object.<anonymous> (vendor.bundle.js:6793)
    at Object.../../../../electron/index.js (vendor.bundle.js:6799)
    at __webpack_require__ (inline.bundle.js:55)
    at Object.../../../../../src/app/utils/ConfigurationUtils.ts (main.bundle.js:399)
    at __webpack_require__ (inline.bundle.js:55)
    at Object.../../../../../src/app/AppComponent.ts (main.bundle.js:21)
    at __webpack_require__ (inline.bundle.js:55)
    at Object.../../../../../src/app/AppModule.ts (main.bundle.js:71)
    at __webpack_require__ (inline.bundle.js:55)
    at Object.../../../../../src/main.ts (main.bundle.js:457)

How can I make it work? I’m pretty new to the Node scene, so… can someone of you explain what’s going on? Thanks…


Did you require() the fs module?
Here’s an example :
const fs = require('fs')


I think I did.

import * as FileSystem from "fs";
FileSystem.readFile( ... );


Ahh yes I forgot you mentioned Angular lol :neutral_face:


So… do someone have a solution? Reading around it seems like the problem is caused by webpack and the fact that it uses its own require implementation, but being new into Node/TS development doesn’t exactly help, so I don’t know what to do.



Did you find a solution? I have the issue when running ipcRenderer.on() with my Angular application. :frowning:


same here, help would greatly be appreciated. :slight_smile:


I also need help in this regard see this and help me out Escort Chandigarh


helped me