I'm trying to create my first Electron app. I've decided to use following tools/technologies:
- TypeScript
- WebPack (version 3)
- React
Local environment is OS X High Sierra.
The problem is that I can't even build my app and I get error on building with WebPack: "Module not found: Error: Can't resolve 'fs' in '<root>/node_modules/electron'
"
I have configuration given below: package.json:
"dependencies": {
"electron": "^1.7.11"
},
"devDependencies": {
"ts-loader": "^3.3.1",
"tslint": "^5.9.1",
"typescript": "^2.6.2",
"webpack": "^3.10.0"
}
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"noImplicitAny": true,
"outDir": "./dist/",
"sourceMap": true,
"target": "es2015"
}
}
webpack.config.js:
const path = require('path');
module.exports = {
entry: './src/index.ts',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
// node: {
// 'fs': 'empty'
// },
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
Finally, my only source code file (./src/index.ts
) taken from electron tutorial looks like:
import { app, BrowserWindow } from 'electron';
import * as path from 'path';
import * as url from 'url';
let win: Electron.BrowserWindow;
function createWindow () {
// ... common stuff
}
app.on('ready', createWindow);
app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); }});
app.on('activate', () => { if (win === null) { createWindow(); }});
I assume that the problem is in the way of TypeScript usage because if I put such code from index.ts to the plain js file, it works correctly (replacing 'import' with 'require').
Thanks for any help in advance!
Update
If set { target: 'node', }
in webpack.config.js
then there is no error on building step, but if I try to open app I get:
App threw an error during load
Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
reinstalling of node modules doesn't help.