title: Electron and TypeScript: 'fs' can't be resolved
body: <p>I'm trying to create my first Electron app. I've decided to use following tools/technologies:</p>
  
  <ul>
  <li>TypeScript</li>
  <li>WebPack (version 3)</li>
  <li>React</li>
  </ul>
  
  <p>Local environment is OS X High Sierra.</p>
  
  <p>The problem is that I can't even build my app and I get error on building with WebPack: "<code>Module not found: Error: Can't resolve 'fs' in '&lt;root&gt;/node_modules/electron'</code> "</p>
  
  <p>I have configuration given below:
  package.json:</p>
  
  <pre><code>  "dependencies": {
      "electron": "^1.7.11"
    },
    "devDependencies": {
      "ts-loader": "^3.3.1",
      "tslint": "^5.9.1",
      "typescript": "^2.6.2",
      "webpack": "^3.10.0"
    }
  </code></pre>
  
  <p>tsconfig.json:</p>
  
  <pre><code>{
    "compileOnSave": false,
    "compilerOptions": {
      "allowJs": true,
      "jsx": "react",
      "moduleResolution": "node",
      "noImplicitAny": true,
      "outDir": "./dist/",
      "sourceMap": true,
      "target": "es2015"
    }
  }
  </code></pre>
  
  <p>webpack.config.js:</p>
  
  <pre><code>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')
      }
  };
  </code></pre>
  
  <p>Finally, my only source code file (<code>./src/index.ts</code>) taken from electron tutorial looks like:</p>
  
  <pre><code>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', () =&gt; { if (process.platform !== 'darwin') { app.quit(); }});
  app.on('activate', () =&gt; { if (win === null) { createWindow(); }});
  </code></pre>
  
  <p>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').</p>
  
  <p>Thanks for any help in advance! </p>
  
  <p><strong>Update</strong></p>
  
  <p>If set <code>{ target: 'node', }</code> in <code>webpack.config.js</code> then there is no error on building step, but if I try to open app I get: </p>
  
  <pre><code>App threw an error during load
  Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
  </code></pre>
  
  <p>reinstalling of node modules doesn't help.</p>