How can I use node “fs” in electron within angular 5

旧巷老猫 提交于 2019-12-05 12:40:09

I found the answer with the help of the comments from kimy82!

First i needed to get the Angular5 webpack.config.js by simply using:

ng eject

After that i opened up the webpack.config.js and added the following:

"target": "node-webkit"

Simply "node" did not work out for me and since electron uses a Chromium this should be ok.

Thanks everyone!

You can also use remote.require to load native node modules from ngx-electron.

fs;

constructor(private _electronService: ElectronService) { 
    this.fs = this._electronService.remote.require('fs');
}

Your browser cannot access the file system on the server. fs should not be loaded in the browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!