node.js - Accessing filesystem in Angular 2 app using Electron -


i know angular 2 run on web browser, not have access file system.

however, i'm using electron front-end, , running app via electron:

"build-electron": "ng build --base-href . && cp src/electron/* dist", "electron": "npm run build-electron && electron dist" 

therefore, run npm run electron @ end runs electron dist.

since i'm running through electron , not ng think should able access filesystem. however, when do:

import * fs 'fs'

i error:

ng:///appmodule/appcomponent_host.ngfactory.js:5 error typeerror: __webpack_imported_module_0_fs__.readfilesync not function(…)

similarly, when try: var fs = require('fs');

i get:

ng:///appmodule/appcomponent_host.ngfactory.js:5 error typeerror: fs.readfilesync not function

this call resulting in error:

this.config = ini.parse(fs.readfilesync('../../config.ini', 'utf-8'))

does have idea what's causing this?

thanks.

as understand it, build application webpack.

you can expose node modules via externals array in webpack config.

module.exports = {    "externals": {       "electron": "require('electron')",       "child_process": "require('child_process')",       "fs": "require('fs')",       "path": "require('path')",       ...    } } 

since provided through webpack externals, 1 not have require them use them imports.

import * fs 'fs' 

you can read more problem in my article.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -